Subject Re: The First to select
Author Adam
--- In firebird-support@yahoogroups.com, "Marvin" <gallagher_98@...>
wrote:
>
> Hi guys,
> I'm wondering if anyone out there knows the inside workings of the
> select FIRST(x) mechanism.
> My question is, In a complex select First query with inner joined
> tables, does firebird do the required calculation and comparing to
> attain the first X num of records, then stop executing and return the
> results OR does the required calculation and comparing for ALL records
> but only returns the first X??

The select first syntax usually requires an order by clause to have
real meaning. If the order by clause has a supporting index, then it
can simply read the first X records based on that index. If it cant use
an index, then it will do the joins first (in all the cases I have
observed). If no order by is used, then it only reads the first X
records.

The Skip Y syntax forces the first Y to be compared etc but does not
display them. (in case you are wondering).

There may be some exceptions, but this is what I have observed.

Adam