0

I am troubleshooting a slow query, it runs in less than 100 ms 99% of the time, but once in an hr (or two no pattern, i guess), goes bad and does 6 million reads and takes 11 seconds! I saw the query plan, it does do a clustered index scan, I noticed the cached_plans dynamic management view use counts column keeps increasing every time the query executes, so i am thinking its the same plan, just wondering why at one point it goes out-of-whack! any pointers will be helpful. I haven't tried anything as it runs pretty fast most of the time.

4

1 回答 1

1

首先,某些东西很容易阻塞查询,使其运行缓慢。Otr 可能同时发生在服务器上的其他事情正在消耗其大部分资源。

接下来,查询的参数可能对保存的执行计划不利。

或者统计数据可能已过时

或者,如果查询是操作查询而不是选择查询,则特定参数可能会导致触发器出现问题,从而使其花费更长的时间。

或者查询有时可能会返回更多的结果。如果您在 10 点运行它并返回 10 个结果,并且导入会在表中放入更多满足查询条件的记录,那么在 10:30 您可能会返回一百万个结果,这显然会更慢。

在这种情况下我喜欢做的一件事是设置日志记录,以便在执行时记录确切的查询。然后,如果您有 varible ,您可以看到运行速度较慢的查询是什么,而不是每次运行都不同。

于 2013-06-28T19:09:48.337 回答