简体   繁体   English

改善不良的间歇SQL查询性能

[英]Improving poor intermittent SQL query performance

I have a moderately complex nested T-SQL query, which for the most part has good performance, except at the start of each of my 2-week pay periods (where there are fewer records to process!) the query bogs down orders of magnitude slower. 我有一个中等复杂的嵌套T-SQL查询,该查询在大多数情况下都具有良好的性能,除了在我的两周薪水周期的开始(其中要处理的记录更少!)的查询之外,查询陷入了数量级的下降。慢点。 Then at some point in the bi-weekly period, SQL Server (2008) determines the execution plan should change and everything is back to normal speeds. 然后,在每两周一次的某个时候,SQL Server(2008)确定执行计划应该更改,并且一切恢复正常。 I have the execution plans for the "good" and "bad" scenarios, but I am a n00b in this area and I do not know how to interpret them. 我有“好”和“坏”方案的执行计划,但是我在这方面是个n00b,我不知道如何解释它们。 What is the next step for me here? 对我来说,下一步是什么? Post the query? 发布查询? The execution plans? 执行计划? Read some articles/book? 看了一些文章/书?

Try updating statistics on the tables in the query at the start of the 2 week period: 尝试在2周的时间段开始时更新查询表中的统计信息:

DBCC UPDATE STATISTICS table-name DBCC UPDATE STATISTICS表名

there are some options, like WITH FULLSCAN you could experiment with as well. 有一些选项,例如WITH FULLSCAN,您也可以尝试。 Take a look in the SQL Server docs. 看一下SQL Server文档。

I got some help over at answers.sqlperformance.com, and while UPDATE STATISTICS <table> does help, it appears to be masking the real problem. 我在Answers.sqlperformance.com上获得了一些帮助,尽管UPDATE STATISTICS <table>确实有帮助,但它似乎掩盖了实际问题。 I was using the constructs (SELECT COUNT(*) ...) = 0 and (SELECT * ...) IS NULL when I should have been using NOT EXISTS (SELECT * ...) . 当我应该一直使用NOT EXISTS (SELECT * ...)时,我正在使用(SELECT COUNT(*) ...) = 0(SELECT * ...) IS NULL的构造。 Changing these resulted in almost another order of magnitude improvement in all cases. 在所有情况下,更改这些参数都将导致几乎另一个数量级的改进。 It looks like the SQL Plan Optimizer is able to work much better in this case. 在这种情况下,SQL Plan Optimizer看起来可以更好地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM