Azure sql query is slow when an indexed column used in where clause has a particular value

北城余情 提交于 2019-12-06 12:58:20

Most likely you are getting very different query plans for these two parameters. As such one performs significantly better than the other. One way to check would be to get your actually execution plan and check it out.

You can do that by pushing the Include Actual Execution Plan button in SSMS (about seven to the left of the Execute button) https://msdn.microsoft.com/en-us/library/ms189562.aspx

As said by Neil though, you will traditionally fix a poor execution plan with updating stats. You will want to update with fullscan though to get the best possible results, you can do that by running this query:

DECLARE @sql nvarchar(MAX);
SELECT @sql = (SELECT 'UPDATE STATISTICS [' + DB_NAME() + '].[' + rtrim(sc.name) + '].[' + rtrim(so.name) + '] WITH FULLSCAN, ALL; '
from sys.sysobjects so
join sys.schemas sc
on so.uid = sc.schema_id
where so.xtype = 'U' 
               FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)');
PRINT @sql
EXEC (@sql)

Hopefully that helps out!

I had a similar issue that was fixed by running exec sp_updatestats. I had to run it on each table in the complex query. I guess the query index on one of the tables was corrupt.

In your case the command would be UPDATE STATISTICS candidates

Thomas LaRock's article covers this in more depth.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!