Subject Re: [firebird-support] Optimizing SELECT DISTINCT ..
Author Douglas Tosi
On Tue, Feb 3, 2009 at 10:15 AM, Harriv <harriv@...> wrote:
> On Tue, Feb 3, 2009 at 1:27 PM, Douglas Tosi <douglasht@...> wrote:
>> On Tue, Feb 3, 2009 at 9:11 AM, Harri Vartiainen <harriv@...> wrote:
>>> What would be best way to optimize "SELECT DISTINCT FIELD1 FROM
>>> TABLE1 ORDER BY FIELD1" query?
>>
>> Not sure if it's the best, but try:
>> SELECT FIELD1 FROM TABLE1 GROUP BY FIELD1
>> This should use the index for an ordered fetch.
>
> Yes it does, but according to statistics it still reads whole table.
> The number just moves from "Non-indexed" to "Indexed" in DBWorkbench.

Firebird does not retrieve field values from the index because indexes
do not contain transaction information.
That's why it has to read the whole table in this case.

1+ 3rd nf

hth,
--
Douglas Tosi
www.sinatica.com