Subject Re: [firebird-support] where Afield in (a subselect) inefficient???
Author Arno Brinkman
Hi,

> Is the following query very inefficient as the subselect clause run
> as many times as records matched in ?
>
> SELECT some_fields_in_table_a FROM table_a TA
> WHERE TA.one_indexed_field = some_value
> AND TA.another_indexed_field IN (SELECT pkey FROM table_b);
>
> I hope the subselect will only run once.

No, the sub-select will be executed for every record inside table_a, but in
a form of :
EXISTS(SELECT pkey FROM table_b WHERE table_b.pkey =
TA.another_indexed_field)
If there is an index available on table_b.pkey (That is so,because that's
the PK :-) that one will be used as you can see in the PLAN.


Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird links :
http://www.firebirdsql.com
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/


Nederlandse firebird nieuwsgroep :
news://80.126.130.81