Subject Re: slow to execute sub-query when "select first x" is used
Author Helen Borrie
--- In firebird-support@yahoogroups.com, "Charles McAllister"
<charles@...> wrote:
>
> i'm using FB version 2.1.1.17910; classic version
>
> i have two simple tables defined, "master" and "detail"
> each has a primary key on column "recno", and table "detail" has an
> index on a column named "master"
>
> i've loaded the "master" table with about 5000 rows, and the "detail"
> table with 100 rows per each master -- so a total of 500k rows
>
> this query executes within milliseconds:
>
> select * from detail where detail.master in
> (select recno from master where master.recno > 1 and master.recno <
> 500 order by recno)
>
> whereas this query executes in over 10 seconds
>
> select * from detail where detail.master in
> (select first 10 recno from master where master.recno > 1 and
> master.recno < 500 order by recno)
>
> i need the second query to execute much faster.
> i know i can accomplish something similar using join, but i really
> need this to work for sub-select as i have a lot of source code
> already written for sub-selects.

Hmmm, so what kind of miracle do you have in mind to make this
monstrosity go faster without writing a better query?

./heLen