如何减少“执行次数”在 MS SQL 执行计划中
有谁知道如何减少在 MS SQL Server 中 SQL 查询的执行计划中看到的“执行次数”?
我们有一个查询在一台生产服务器上运行缓慢(其他服务器很好)。在检查执行计划时,我们看到第一个步骤是聚集索引扫描。在运行良好的服务器上,此扫描会执行一次。在运行缓慢的那一个上,它执行了 4 次。
我们在这里阅读(http://www.sql-server-performance.com/ Tips/query_execution_plan_analysis_p2.aspx),您应该尝试减少它,但我们找不到任何有关如何执行此操作的提示。
两台服务器都运行相同版本的 Windows (2003) 和 SQL Server (2000)。
任何帮助将不胜感激。
Does anyone know how to reduce the 'Number of executions' you can see in the execution plan of a SQL Query in MS SQL Server?
We have a query that runs slow on one production server (others are fine). When checking the execution plan, we see that one of the first steps is a Clustered Index Scan. On the servers that run fine, this scan is executed once. On the one that runs slow, it is executed 4 times.
We read here (http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p2.aspx) that you should try to reduce it, but we can't find any tips on how to do this.
Both servers run the same version of Windows (2003) and SQL Server (2000).
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据库架构真的相同吗?如果是这样,请尝试更新统计信息并对索引和表进行碎片整理。
http://msdn.microsoft.com/en-us /library/aa260645(SQL.80).aspx
http:// /technet.microsoft.com/en-us/library/cc966523.aspx
Is the db schema really the same? If it's so then try to update statistics and defrag your indexes and tables.
http://msdn.microsoft.com/en-us/library/aa260645(SQL.80).aspx
http://technet.microsoft.com/en-us/library/cc966523.aspx
抱歉,我自己来回答这个问题。感谢亚瑟提供的链接,它们很有用(所以我对你的答案投了赞成票)。我们更新了统计数据,但没有帮助。我们使用 DBCC SHOWCONTIG 检查了碎片整理,但它与其他数据库没有太大不同。
我很抱歉没有发布查询 AdaTheDev,但我必须更改所有列和内容(因为它是相当关键的业务内容),我们现在找到了解决方案。
我们注意到该表的记录比其他数据库多得多。我们在正确的列上添加了索引。我们做了这样的连接:
所以我们为每个 Id 列添加了三个单独的索引,这将其速度从 30 秒缩短到 3-5 秒(尽管我们确实在 t1Id 和 someOtherId 上有一个索引)。
最后我们还对表做了清理,因为很多记录被逻辑删除了,不再需要了。但指数成功了。
Sorry I'm answering this myself. Thanks Arthur for the links, they were useful (so I up-voted your answer). We updated the statistics but it didn't help. We checked the defragmentation with DBCC SHOWCONTIG, but it wasn't very different from the other databases.
I'm sorry for not posting the query AdaTheDev, but I'd have to change all the columns and stuff (because it's fairly business critical stuff), and we've found a solution now.
We noticed the table had much more records than the other databases. We added indexes on the correct columns. We did a join like:
So we added three separate indexes for each Id column, which sped it up from 30s to 3-5s (we did have an index on t1Id and someOtherId together though).
In the end we also did a clean up of the table, because a lot of records were logically deleted and no longer necessary. But the indexes did the trick.