It is fairly widely known that implicit conversions of data types can cause scans. However, you may not be able to control what goes in your database, you may have inherited an app and we just are not perfect.
On top of that some can be tricky. For example, did you know that scope_identity and @@identity both return numeric data types. An AVG of a SMALLINT column returns an INT.
Here is a simple repro which the same query does an index scan instead of an index seek
CREATE TABLE t1( id INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, c1 VARCHAR(100) ) GOINSERT INTO t1(c1) SELECT 1GO 10000INSERT INTO t1(c1) SELECT 0GO 10CREATE INDEX ix ON t1 (c1) CREATE PROC p1@blah NVARCHAR(100) ASSELECT id FROM t1WHERE c1 = @blahEXEC p1 N'0'CREATE PROC p2 @blah VARCHAR(100) ASSELECT id FROM t1WHERE c1 = @blahEXEC p2 '0'DROP TABLE t1DROP PROC p1DROP PROC p2
I found a sample query from Umachandar Jayachandran and made some mod’s to it. It basically scans your procedure cache for index scans containing implicit conversions.
I have posted it at the SQLServerPedia Wiki here. It is the 2nd query listed.
Note: Implicit conversions may not always result in a scan.
posted @ Monday, January 12, 2009 11:55 PM by Uri
posted @ Tuesday, January 13, 2009 1:21 PM by Sankar Reddy
posted @ Tuesday, January 13, 2009 1:34 PM by Sankar Reddy
posted @ Tuesday, January 13, 2009 1:42 PM by JasonMassie
posted @ Sunday, January 18, 2009 11:25 AM by Andrew Calvett
posted @ Wednesday, January 21, 2009 1:16 AM by Michael Zilberstein
posted @ Friday, January 30, 2009 7:33 AM
posted @ Monday, September 14, 2009 1:41 PM by Erland Sommarskog
Name (required)
Email (required)
Website
Notify me of followup comments via e-mail