SQL optimization:Implicit Conversion will cause index scan instead of index seek.

来源:互联网 发布:网络舆情分析系统 编辑:程序博客网 时间:2024/04/19 03:23

1.  Implicit Conversion will cause index scan instead of index seek.

SELECT a

FROM dbo.TeletedAS GP

WHERE principalId =@temp

Note: principalId date type is uniqueidentifier; but the @temp type is nvarchar.


Fix:

way 1: ensure the 2 have same data type.

way 2: we can use explicit conversion.


Note: Not all implicit conversion will lead to index scan instead of index seek.

For more info, you can see the posthttps://www.sqlskills.com/blogs/jonathan/implicit-conversions-that-cause-index-scans/ 

https://msdn.microsoft.com/en-us/library/ms191530.aspx (Date type conversion)


Why can implicit conversion lead to index scan instead of index seek?

From execution plan, I know sql optimizer try to implicitly convert principalId, not @temp, that is why it only use index scan. (stupid work, right?)




0 0