FIX: Poor Performance with In Clause Using Multiple Correlated Subqueries Unioned Together

This article was previously published under Q243211
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 56516 (SQLBUG_70)
SYMPTOMS
A query containing an IN clause of correlated subqueries that are unioned together performs slower on SQL Server 7.0 than on SQL Server 6.5 when the correlation clauses are redundant.
WORKAROUND
Remove the redundant correlation from the subqueries.
STATUS
Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0
For more information, contact your primary support provider.
MORE INFORMATION
The following is an example of the type of query that performs poorly:
Select a from table1 where a  IN(    ( SELECT table2.a       FROM table2, table3       WHERE (table2.a = table1.a)      AND (table2.b = table3.b)    )UNION    ( SELECT C.Contact_Id       FROM table1 C, table4       WHERE (C.e = "value")       AND C.d = table4.d      AND (table1.a = C.a)    ))				
The above query can rewritten as follows:
Select Contact_Id from table1 where contact_id  IN(    ( SELECT table2.a       FROM table2, table3       WHERE (table2.b = table3.b)    )UNION    ( SELECT C.a       FROM table1 C      WHERE (C.e = "value")    ))				
Properties

Article ID: 243211 - Last Review: 10/22/2013 01:17:10 - Revision: 2.1

  • Microsoft SQL Server 7.0 Standard Edition
  • kbnosurvey kbarchive kbbug kbfix KB243211
Feedback