简体   繁体   English

SQL 服务器执行计划

[英]SQL server execution plan

How can I capture SQL execution plan for queries.如何捕获 SQL 查询执行计划。 Someone told that I can retrieve them through system tables有人告诉我可以通过系统表检索它们

As gbn points out, there are a number of different ways that you can review the execution plans for queries. 正如gbn指出的那样,您可以通过多种不同方式来查看查询的执行计划。 Given that your question makes reference to the use of system tables I assume that your are talking about the Dynamic Management Views (DMV's) and that your are therefore also only interested in query plans that are currently in the plan cache. 鉴于您的问题涉及系统表的使用,我假设您正在谈论动态管理视图(DMV),因此您也仅对计划缓存中当前的查询计划感兴趣。

If you are interested in identifying the query plan for a specific query from the plan cache then you can use a query of the form like below: 如果您有兴趣从计划缓存中为特定查询标识查询计划,则可以使用如下形式的查询:

SELECT  deqs.plan_handle ,
        deqs.sql_handle ,
        execText.text
FROM    sys.dm_exec_query_stats deqs
        CROSS APPLY sys.dm_exec_sql_text(deqs.plan_handle) AS execText
WHERE   execText.text LIKE '%QueryText%'

For further reading, take a look at the article DMVs for Query Plan Metadata 为了进一步阅读,请查看文章查询计划元数据的DMV。


If say you are more interested in reviewing the performance of your most poorly performing queries, that are currently referenced in the plan cache, you can make use of the excellent and freely available SQL Server Performance Dashboard Reports. 如果说您对查看计划缓存中当前引用的性能最差的查询的性能更感兴趣,则可以利用出色且免费的SQL Server性能仪表板报告。


There are of course other methods for viewing query plans but without knowing exactly what it is that you are trying to achieve, these may not be appropriate to your needs. 当然,还有其他查看查询计划的方法,但是在不完全知道您要实现的目标的情况下,这些方法可能不适合您的需求。

Quick search on MSDN will get you this: http://msdn.microsoft.com/en-us/library/ms189747.aspx 在MSDN上的快速搜索将为您提供: http : //msdn.microsoft.com/zh-cn/library/ms189747.aspx

Hope it helps. 希望能帮助到你。

This question could be clearer but I imagine some people coming here might be looking for the easiest way to get an execution plan for a query这个问题可能更清楚,但我想有些人来这里可能正在寻找最简单的方法来获取查询的执行计划

The easiest way to capture the execution plan of a query is to click the "Include Actual Execution Plan" button and execute the query on SSMS捕获查询执行计划的最简单方法是单击“包括实际执行计划”按钮并在 SSMS 上执行查询

包括实际执行计划按钮

Results will be displayed as a tab together with the query results结果将与查询结果一起显示为选项卡

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

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