SQL Server中的执行计划有什么用?

发布于 2024-08-23 05:30:57 字数 42 浏览 9 评论 0原文

SQL Server中的执行计划有什么用?这些计划什么时候可以帮助我?

What is the usage of Execution Plan in SQL Server? When can these plans help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

長街聽風 2024-08-30 05:30:57

当您的查询都运行得很快时,世界上一切都很好,执行计划并不那么重要。然而,当某些东西运行缓慢时,它们就非常重要。它们主要用于帮助调整(加速)慢速 SQL。如果没有执行计划,您只能猜测要更改哪些内容才能使 SQL 运行得更快。

这是他们可以帮助您的最简单的方法。进行慢查询并在 SQL Server Management Studio 查询窗口中执行以下操作:

1) 运行命令:

SET SHOWPLAN_ALL ON 

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:

SET SHOWPLAN_ALL ON 

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 word SCAN 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.

阳光①夏 2024-08-30 05:30:57

这些计划描述了 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).

晨敛清荷 2024-08-30 05:30:57

当您需要对特定查询执行性能分析时。

查看 SQL Server 查询执行计划分析

到了分析的时候
特定查询的性能,一
最好的方法是查看
查询执行计划。一个查询
执行计划概述了 SQL 如何执行
服务器查询优化器实际运行
(或将运行)特定查询。这
信息如果非常有价值
是时候找出具体原因了
查询运行缓慢。

When you need to perform performance profiling on a specific query.

Have a look at SQL Server Query Execution Plan Analysis

When it comes time to analyze the
performance of a specific query, one
of the best methods is to view the
query execution plan. A query
execution plan outlines how the SQL
Server query optimizer actually ran
(or will run) a specific query. This
information if very valuable when it
comes time to find out why a specific
query is running slow.

染墨丶若流云 2024-08-30 05:30:57

它有助于确定长时间运行的查询中出现瓶颈的位置。只需了解服务器如何执行复杂查询,您就可以实现一些令人印象深刻的性能改进。

如果我没记错的话,它还可以识别出良好的索引候选者,这是提高性能的另一种方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文