Subject Re: [firebird-support] Limiting fetched rows doesn't offer much performance benefit
Author Ivan Prenosil
> We are trying to query a very large table (millions of records) and
> only retrieve a few rows using "FIRST n". From our tests, "SELECT
> FIRST 50 * FROM TABLE WHERE FLAG='Y'" doesn't run significantly faster
> than "SELECT * FROM TABLE WHERE FLAG='Y'". The FLAG field is combined
> in a compound index with a unique record number to avoid low selectivity.

Since you use only one field in WHERE clause, adding another field to the index
can't speed up SELECT statement. Your problem is that either
- there are really too much 'Y' values in FALG field (thus dropping the index should help), or
- you have incorrect order of fields in index' definition, it must be (FLAG, PK), not (PK, FLAG)

Ivan
http://www.volny.cz/iprenosil/interbase/