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

This article was previously published under Q292637
This article has been archived. It is offered "as is" and will no longer be updated.
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 theMicrosoft 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 pubsGOCREATE TABLE t1( c1 nvarchar(25) )GOCREATE CLUSTERED INDEX idx ON t1(c1)GO				
SET SHOWPLAN_TEXT ONGOSELECT * 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
7 more greater seven inequality character char varchar
Properties

Article ID: 292637 - Last Review: 01/16/2015 21:59:09 - Revision: 3.2

  • Microsoft SQL Server 2000 Standard Edition
  • kbnosurvey kbarchive kbbug kbfix kbsqlserv2000sp1fix KB292637
Feedback