Microsoft KB Archive/292637

= FIX: Unicode Character String Longer Than Seven Bytes in a LIKE Clause Is Truncated in Execution Plan =

Article ID: 292637

Article Last Modified on 10/16/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q292637



BUG #: 350911 (SHILOH_BUGS)



SYMPTOMS
When you use a Unicode character data type for a column, if a query contains a character string that is longer than seven characters inside a LIKE clause, the execution plan will only consider the first seven characters. Therefore, the optimizer may choose a less than optimal plan if those first seven characters are not selective.



RESOLUTION
To resolve this problem, obtain the latest service pack for SQL Server 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

290211 INF: How to Obtain the Latest SQL Server 2000 Service Pack



WORKAROUND
Use >= and <= instead of a LIKE clause.



STATUS
Microsoft has confirmed that this is a problem in SQL Server 2000. This problem was first corrected in SQL Server 2000 Service Pack 1.



MORE INFORMATION
The following script demonstrates the problem: USE pubs GO

CREATE TABLE t1( c1 nvarchar(25) ) GO CREATE CLUSTERED INDEX idx ON t1(c1) GO SET SHOWPLAN_TEXT ON GO

SELECT * FROM t1 WHERE c1 LIKE '123456789%' The execution plan is as follows:

StmtText

---


 * --Clustered Index Seek(OBJECT:([pubs].[dbo].[t1].[idx]), SEEK:([t1].[c1] >= '1234567' AND [t1].[c1] < '1234568'), WHERE:(like([t1].[c1], '123456789%', NULL)) ORDERED FORWARD)

After applying the latest service pack, the new execution plan for the same query is as follows:

StmtText

---


 * --Clustered Index Seek(OBJECT:([pubs].[dbo].[t1].[idx]), SEEK:([t1].[c1] >= '123456789' AND [t1].[c1] < '12345678?'), WHERE:(like([t1].[c1], '123456789%', NULL)) ORDERED FORWARD)

For additional information on the same problem on SQL Server 7.0, click the article number below to view the article in the Microsoft Knowledge Base:

278656 PRB: Like Predicate Optimization is Limited to 7 Character Positions

Additional query words: 7 more greater seven inequality character char varchar

Keywords: kbbug kbfix kbsqlserv2000sp1fix KB292637

-

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

© Microsoft Corporation. All rights reserved.