Subject | Re: [firebird-support] Re: Natural plan on indexed column |
---|---|
Author | Matthias Hanft |
Post date | 2006-03-27T08:00:52Z |
Svein Erling Tysvær wrote:
MAX value by an ascending index, too ("just use the last index
entry"), but maybe I have not understood the index concept fully
yet :-)
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
> You're right in that min(datetime) may use your index, but sinceYou're right. I thought it would be easy for Firebird to get the
> 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.
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.Done. Here are the results:
> Then I'd expect Firebird to use both indexes. Though don't take my
> word for it (I haven't tried) - test it yourself.
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