Subject Re: [firebird-support] Re: Natural plan on indexed column
Author Matthias Hanft
Svein Erling Tysvær wrote:

> You're right in that min(datetime) may use your index, but since
> indexes are unidirectional, you have no index to use with
> max(datetime). Having to look through every record to find the
> maximum, Firebird simply doesn't bother to use the index to find the
> minimum.

You're right. I thought it would be easy for Firebird to get the
MAX value by an ascending index, too ("just use the last index
entry"), but maybe I have not understood the index concept fully
yet :-)

> Try adding another index, a DESCending index on your timestamp column.
> Then I'd expect Firebird to use both indexes. Though don't take my
> word for it (I haven't tried) - test it yourself.

Done. Here are the results:

select min(datetime) --->>> uses ascending index
select max(datetime) --->>> uses descending index
select min(datetime), max(datetime) --->>> uses natural?!?!?!

I cannot believe that it is faster to read all rows than just
using two indexes, one after another?!

Matthias