Subject Re: [firebird-support] Simple SQL question
Author bartsmissaert@blueyonder.co.uk
Thanks for clarifying, I can see this now.

RBS


> Hi,
>
>> FB 1.5 Classic on Windows.
>> Just wondering about the difference in speed in these 2 simple queries:
>>
>> select max(field1) from table1
>>
>> select max(field1) from table1 where field1 > 1000000
>>
>> The second one being a lot faster.
>>
>> The point is that this field has a unique ascending index, so if I do
>> the
>> simple phonebook analogy why is it faster to look at the last entry in
>> the
>> book or the last entry, but saying the name has to be > zaaa
>
> Considering the phonebook:
> You can only go to the last entry by going through them all -unless- you
> know a way of skipping to the last entry and going backward, which is
> what a DESCending index does.
>
> So, given the phonebook, it's much faster to start at ZAAA and find
> the "last entry" by going from ZAAA to ZZZZ then by starting at
> AAAA and then going to ZZZZ.
>
> Martijn Tonies
> Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Sybase
> SQL Anywhere, Oracle & MS SQL Server
> Upscene Productions
> http://www.upscene.com
> My thoughts:
> http://blog.upscene.com/martijn/
> Database development questions? Check the forum!
> http://www.databasedevelopmentforum.com
>
>