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

Article translations Article translations
Article ID: 292637 - View products that this article applies to.
This article was previously published under Q292637
BUG #: 350911 (SHILOH_BUGS)
Expand all | Collapse all

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

Properties

Article ID: 292637 - Last Review: October 16, 2003 - Revision: 3.2
APPLIES TO
  • Microsoft SQL Server 2000 Standard Edition
Keywords: 
kbbug kbfix kbsqlserv2000sp1fix KB292637

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com