Subject Re: [firebird-support] Re: Optimize max query in select
Author Svein Erling Tysvaer
diwic2 wrote:
>>> select nodeid, max(pid)+1 as q
>>> from my_messages group by nodeid
>>>
>> Have you tried creating a descending index on the field you
> calculate
>> the max() for?
>
> CREATE DESCENDING INDEX "INDEX1" ON "MY_MESSAGES"("PID");
>
> Yes. It does not change the plan (i e it does not use the index).
>
> PLAN (MY_MESSAGES ORDER RDB$PRIMARY3)

Are you sure it doesn't use the index anyway? Firebird 1.5 doesn't
always tell the full truth about how it utilizes tables, and I think it
is in those cases when it displays the PLAN used for ordering and
doesn't bother to tell you whether indexes are used before you get to
that point. Admittedly, I think my experience is based on indexes useful
for the WHERE or JOIN clause rather than MAX, but I wouldn't have
concluded that the index isn't used until I'd actually timed the query
with and without the index present.

HTH,
Set