SQL Server中的执行计划有什么用?
SQL Server中的执行计划有什么用?这些计划什么时候可以帮助我?
What is the usage of Execution Plan in SQL Server? When can these plans help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您的查询都运行得很快时,世界上一切都很好,执行计划并不那么重要。然而,当某些东西运行缓慢时,它们就非常重要。它们主要用于帮助调整(加速)慢速 SQL。如果没有执行计划,您只能猜测要更改哪些内容才能使 SQL 运行得更快。
这是他们可以帮助您的最简单的方法。进行慢查询并在 SQL Server Management Studio 查询窗口中执行以下操作:
1) 运行命令:
2) 运行慢查询
3) 您的查询将不会运行,但将返回执行计划。
4) 在
PhysicalOp
列输出中查找此列中任何文本中的单词SCAN
,这通常是查询的一部分导致速度放缓。分析与该输出行有关的连接和索引使用情况,如果可以消除扫描,通常会提高查询速度。输出中可能有有用的列(TotalSubTreeCost 等),当您学习如何读取执行计划和调整慢速查询时,您将熟悉它们。
When your queries all run fast, all is good in the world and execution plans don't really matter that much. However, when something is running slow, they are very important. They are primarily used to help tune (speed up) slow SQL. Without execution plans, you'd just be guessing at what to change to make your SQL go faster.
Here is the simplest way they can help you. Take a slow query and do the following in a SQL Server Management Studio query window:
1) run the command:
2) run your slow query
3) your query will not run, but the execution plan will be returned.
4) look through the
PhysicalOp
column output for the wordSCAN
within any text in this column, this is usually the part of the query that is causing the slowdown. Analyze your joins and index usage in regards to this row of the output and if you can eliminate the scan, you will usually improve the query speed.There are may useful columns (TotalSubTreeCost, etc) in the output, you will become familiar with them as you learn how to read execution plans and tune your slow queries.
这些计划描述了 SQL Server 如何执行您的查询。这是 SQL Server 查询优化器基于成本的算法的结果,该算法提出了如何以预期的最佳方式获得最终结果的计划。
它很有用,因为它会向您显示查询中的时间花费在哪里、是否使用索引、对这些索引执行什么类型的处理(扫描、查找)等。
因此,如果您的查询性能不佳,执行计划将突出显示成本最高的部分,并允许您查看哪些部分需要优化(例如,可能缺少索引,可能是写入效率低下的查询,导致索引扫描而不是查找)。
These plans describe how SQL Server goes about executing your query. It's the result of a cost-based algorithm by the SQL Server query optimiser, which comes up with a plan for how to get to the end result in the expected best possible way.
It's useful because it will show you where time is being spent in the query, whether indexes are being used or not, what type of process is being done on those indexes (scan, seek) etc.
So if you have a poorly performing query, the execution plan will highlight what the costliest parts are and allow you to see what needs optimising (e.g. may be a missing index, may be an inefficiently written query resulting in an index scan instead of a seek).
当您需要对特定查询执行性能分析时。
查看 SQL Server 查询执行计划分析
When you need to perform performance profiling on a specific query.
Have a look at SQL Server Query Execution Plan Analysis
它有助于确定长时间运行的查询中出现瓶颈的位置。只需了解服务器如何执行复杂查询,您就可以实现一些令人印象深刻的性能改进。
如果我没记错的话,它还可以识别出良好的索引候选者,这是提高性能的另一种方法。
It's helpful in identifying where bottlenecks are occurring in long running queries. You can make some quite impressive performance improvements simply by knowing how the server executes your complex query.
If I remember correctly it also identifies good candidates for indexing which is another way to increase performance.