Microsoft KB Archive/247125

= FIX: Optimizer May Choose Inefficient Query Plan When Using NOT LIKE with an Empty String =

Article ID: 247125

Article Last Modified on 3/14/2006

-

APPLIES TO


 * Microsoft SQL Server 7.0 Standard Edition

-



This article was previously published under Q247125



BUG #: 56552 (SQLBUG_70)



SYMPTOMS
SQL Server may incorrectly estimate the number of rows returned by a query or subquery using the NOT LIKE comparison operator with the Empty String. This behavior can subsequently cause poor performance on SELECT statements due to inefficient query plans being chosen.

Instead of using the NOT LIKE comparison operator for selecting rows that do not have Empty String values for a column, use the following query: SELECT * FROM orders WHERE shipaddress LIKE '_%' Note that '_' matches any single character, and '%' matches any string of zero or more characters.



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 behavior reported can be observed by running the following query with the Northwind database: SELECT * FROM orders WHERE shipaddress NOT LIKE '' This query returns 830 rows; however, the generated Estimated Execution Plan only estimates a single row returned for the NOT LIKE filter. To display the Estimated Execution Plan for a query, you can select the Display Estimated Execution Plan (CTRL+L) option from the Query Analyzer's toolbar.

Additional query words: sqlserver LIKE Empty String query T-SQL

Keywords: kbbug kbfix KB247125

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.