Subject Re: [firebird-support] Limit the query via time or number of records
Author Ann W. Harrison
On 12/14/2010 12:07 PM, masotti wrote:
> Hi,
> On 14/12/2010 17:09, kokok_kokok wrote:
>> I am building a Web server with Firebird 2.5. There are few clients (<10
>> concurrently) but they can frozen the server if they do not use
>> reasonable limits in their consults (for example they could query 20
>> years of data, it means millions of records).
> To change programaticcally, I'd change
> in critical statements.

That's a risky solution. There are many circumstances in which finding
the first 1000 of something results in Firebird finding all of the
"something", sorting them, and returning the first 1000 in sorted order.
Not at all what is wanted.

To be more specific, unless there is a single index that exactly matches
the order by clause in fields and ascending/descending order, Firebird
finds all qualifying rows and sorts them. In a join query, that index
has to drive the outer loop of a nested loop join.

In the absence of an order by, select first restricts the records
returned, but returns a random set of records - all matching the
criteria, but a random subset.

Good luck,