Subject | RE: [firebird-support] correlated subquery optimize problem under FB 2 |
---|---|
Author | Leyne, Sean |
Post date | 2007-12-06T17:03:38Z |
> My query is quite more complex, but for illustratin - conditionsfrom
> (A.Confirmed = 'A' ) AND (A.Closed = 'N' ) reduced 147 000 records
> Table1 A into something arround 2000 records.========================================================================
>
==
> =======================================In both of your example the above criteria is useless since you already
> 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')
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') )What is the relationship between these fields?
> AND (A.Confirmed = 'A' ) AND (A.Closed = 'N' )
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