Wednesday 2 April 2014

Data Mismatch on WHERE Clause by functions : will cause performance issue?

Yes.It will cause performance issue.
   Any function such as collate, convert, substring etc. applied on a column might make impossible for SQL Server to use any index on this column. This because SQL Server query optimizer considers the column after the function as a new column, because the column values are not stored in the index pages as returned by the function. For these reasons, it is not possible to use indexes on these columns.

This is of course is not only for WHERE clause columns. Join, order, group by or having clause may have same problem. However functions in the select list does not affect index selection.

Some common problematic functions are :

COLLATE
CONVERT
SUBSTRING
LEFT
LTRIM
RTRIM
User defined functions.

No comments:

Post a Comment

First Database In Sql Server