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

ID: Q243211


The information in this article applies to:
  • Microsoft SQL Server version 7.0

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.


RESOLUTION

A supported fix that corrects this problem is now available from Microsoft, but it has not been fully regression tested and should be applied only to systems experiencing this specific problem. If you are not severely affected by this specific problem, Microsoft recommends that you wait for the next SQL Server service pack that contains this fix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information on support costs, please go to the following address on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
The English version of this fix should have the following file attributes or later:

   Date      Time   Version      Size   File name   Platform
   ---------------------------------------------------------
   10/9/99   3:11PM 7.00.738  4,317,084 sqlservr.exe  x86
   10/9/99   3:12PM 7.00.738 11,514,128 sqlservr.exe alpha 
NOTE: Due to file dependencies, the most recent hotfix or feature that contains the above files may also contain additional files.


This fix was implemented using trace flag 8682. To set the trace flag in Enterprise Manager:

  1. Right-click on the server and choose properties.


  2. On the General tab, click Startup Parameters.


  3. Add the following as a new parameter: -T8682


  4. Restart the server and the new parameter takes affect.




NOTE: If this product was already installed on your computer when you purchased it from the Original Equipment Manufacturer (OEM) and you need this fix, please call the Pay Per Incident number listed on the above Web site. If you contact Microsoft to obtain this fix, and if it is determined that you only require the fix you requested, no fee will be charged. However, if you request additional technical support, and if your no-charge technical support period has expired, or if you are not eligible for standard no-charge technical support, you may be charged a non-refundable fee.

For more information about eligibility for no-charge technical support, see the following article in the Microsoft Knowledge Base:
Q154871 Determining If You Are Eligible for No-Charge Technical Support


WORKAROUND

Remove the redundant correlation from the subqueries.


STATUS

Microsoft has confirmed this to be a problem in SQL Server version 7.0.


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")
    )
) 

Additional query words:

Keywords : SSrvTran_SQL kbbug7.00
Version : winnt:7.0
Platform : winnt
Issue type : kbbug


Last Reviewed: December 22, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.