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

>>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?!
>
> I agree with you and am surprised about your findings. Is it the same
> if the table contains 1 million rows with pretty unique datetime values?

Had not yet the time to insert 1 million rows :-) But with some
50,000 rows, it goes like this:

select min(datetime) /* using index */ -> 32 ms
select min(datetime), max(datetime) /* no index */ -> 109 ms

select count(*) /* no index */ -> sometimes 109 ms, sometimes 78 ms
select count(*) where id>0 /* pk index */ -> 94 ms

I guess 50,000 rows are still too few to get some significant
timing measure results. Will try further... (maybe inserting
1 million rows tonight until tomorrow morning :-)

Matthias