Article ID: 243211
Article Last Modified on 3/14/2006
APPLIES TO
- Microsoft SQL Server 7.0 Standard Edition
This article was previously published under Q243211
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") ) )
Keywords: kbbug kbfix KB243211