Subject RE: [firebird-support] correlated subquery optimize problem under FB 2
Author Leyne, Sean
> My query is quite more complex, but for illustratin - conditions
> (A.Confirmed = 'A' ) AND (A.Closed = 'N' ) reduced 147 000 records
from
> Table1 A into something arround 2000 records.
>
========================================================================
==
> =======================================
> SELECT A.ID FROM
> Table1 A
> JOIN Table2 B ON B.ID=A.Firm_ID
> WHERE
>
> A.Firm_ID IN (SELECT ID FROM Table2 WHERE ID='xxxxxxxxxx' OR
> Firm_ID='xxxxxxxxxx')

In both of your example the above criteria is useless since you already
have " JOIN Table2 B ON B.ID=A.Firm_ID" which binds the results to only
those records with A.Firm_ID = B.ID.

Accordingly, your criteria:

A.Firm_ID IN (SELECT ID FROM Table2 WHERE ID='xxxxxxxxxx' OR
Firm_ID='xxxxxxxxxx')

will never have any effect except to needlessly slow down your
statement.


As for improving the SQL performance

> AND (A.DocQueue_ID IN ('3000000101','K400000101') )
> AND (A.Confirmed = 'A' ) AND (A.Closed = 'N' )

What is the relationship between these fields?

Do you commonly query based on these fields? If so, do you use a field
or group of fields in these queries?

Do you have any indexes on these fields? If so, what are they?

Please provide the PLAN which the engine has generated for the queries.

I suspect that you need a couple of well defined indexes, which would
substantially help performance.


Sean