Subject Re: [firebird-support] Slow select min()
Author Kirill Nesterenko
>> I have a query which runs very slow:
>> select min(id) from stat where user_id = 100
>>
>> also if I run select max(id) - it runs immediately.
>
> Here's a piece of info that looks relevant:
>
> Firebird indexes are "one-way" indexes. An ascending index can quickly
> find a maximum value but not a minimum value.
>
> So, to make your first query run as fast as the other one, it looks like
> you need to create a descending index on the ID field. Try it!

No, descending index should affect only max(). (And ascending - min() )
Anyway, I tried to create it - no difference.

Also, I noticed that default plan is
"PLAN (stat ORDER PK_STAT INDEX (STAT_USER_ID))".
But if I change it to the "PLAN (stat INDEX (STAT_USER_ID))" - query runs
immediately..

Kirill.