Article ID: 318530 - View products that this article applies to.
This article was previously published under Q318530
BUG #: 356418 (SHILOH_BUGS)
If you submit a query that contains at least one outer join that has a filter condition in the WHERE clause on the inner table of the outer join (for example, a filter condition on the right table of a left outer join, or the left table of a right outer join), SQL Server may perform less selective joins first instead of performing the outer join early and applying the filter condition. If the filter condition from the outer join is one of the more selective criteria for the query, failing to process the criteria early in the plan may lead to:
Resolution for SQL Server 2005To resolve this problem, obtain the latest service pack for SQL Server 2005. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
913089After you install the SQL Server 2005 service pack, you must turn on trace flag 4101 to resolve this problem.
(http://support.microsoft.com/kb/913089/ )How to obtain the latest service pack for SQL Server 2005
Resolution for SQL Server 2000To resolve this problem, obtain the latest service pack for Microsoft SQL Server 2000. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
290211NOTE: The following hotfix was created before the release of Microsoft SQL Server 2000 Service Pack 3.
(http://support.microsoft.com/kb/290211/ )How to obtain the latest SQL Server 2000 service pack
The English version of this fix should have the following file attributes or later:
NOTE: Because of file dependencies, the most recent hotfix or feature that contains the files may also contain additional files.
Version File name ----------------------------- 8.00.0584 Sqlservr.exe
Status for SQL Server 2005Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
This problem was first corrected in Microsoft SQL Server 2005 Service Pack 1.
Status for SQL Server 2000Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.
This problem was first corrected in Microsoft SQL Server 2000 Service Pack 3.
The following contrived join scenario uses the pubs database to demonstrate the scenario:
Note that the titleauthor table is the right table of a left outer join and the WHERE clause condition on titleauthor that is to be applied after the outer join. The output shows the original, slower query plan, where all the inner joins are performed first and the outer join and filter is performed last, even though it is the most selective condition for the query. The second query plan is a forced plan that demonstrates what the faster plan will look like, in which the outer join and filter is performed first, followed by the remaining inner joins.
For this particular scenario, the optimizer continues to choose the first plan even after you apply the hotfix. This is because these tables are so small and the estimated cost of the first plan is low enough that it is deemed better to just run with that plan than it is to continue searching for subsequent alternatives. As the data in the tables increases, the cost of the first plan becomes higher and the optimizer starts to choose the second plan.
Article ID: 318530 - Last Review: February 4, 2008 - Revision: 5.1
Contact us for more help