SQL Server 相当于 MySQL 的 EXPLAIN
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3449814/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server equivalent to MySQL's EXPLAIN
提问by Ash Burlaczenko
I was reading an SQL tutorial which used the keyword EXPLAIN to see how a query is executed. I tried it in SQL Server 2008 with no success.
我正在阅读 SQL 教程,该教程使用关键字 EXPLAIN 来查看查询是如何执行的。我在 SQL Server 2008 中尝试过,但没有成功。
How do I get the equivalent result?
我如何获得等效的结果?
采纳答案by Justin
I believe that the EXPLAIN
keyword is an MySQL concept - the equivalent Microsoft SQL server concept is the execution plan.
我相信EXPLAIN
关键字是一个 MySQL 概念——等效的 Microsoft SQL 服务器概念是执行计划。
The simplest way of getting an execution plan is to turn on the "Show actual execution plan" menu item (in the query menu) in SQL server management studio. Alternatively you can read a more in-depth guide on execution plans here:
获取执行计划的最简单方法是在 SQL Server Management Studio 中打开“显示实际执行计划”菜单项(在查询菜单中)。或者,您可以在此处阅读有关执行计划的更深入指南:
This article goes into a lot more detail on what execution plans are, how to obtain an execution plan, and the different execution plan formats.
本文详细介绍了什么是执行计划、如何获取执行计划以及不同的执行计划格式。
回答by KM.
MySql EXPLAIN 语句既可以用作 DESCRIBE 的同义词,也可以用作获取有关 MySQL 如何执行 SELECT 语句的信息的方法。
The closest equivalent statement for SQL Server is:
SQL Server 最接近的等效语句是:
SET SHOWPLAN_ALL (Transact-SQL)
or
SET SHOWPLAN_XML (Transact-SQL)
SET SHOWPLAN_ALL (Transact-SQL)
或
SET SHOWPLAN_XML (Transact-SQL)
From a SQL Server Management Studio query window, you could run SET SHOWPLAN_ALL ON
or SET SHOWPLAN_XML ON
and then your query. At that point It will not return the result set of the query, but the actual execution plan. When you then run SET SHOWPLAN_ALL OFF
or SET SHOWPLAN_XML OFF
and then run your query, you will then again get a result set.
在 SQL Server Management Studio 查询窗口中,您可以运行SET SHOWPLAN_ALL ON
或SET SHOWPLAN_XML ON
然后运行您的查询。此时它不会返回查询的结果集,而是返回实际的执行计划。当您然后运行SET SHOWPLAN_ALL OFF
或SET SHOWPLAN_XML OFF
然后运行您的查询时,您将再次获得一个结果集。
回答by Mike
Be aware that Microsoft added an EXPLAIN command to TSQL syntax in SQL 2012, however it only applies to Azure SQL Data Warehouse and Parallel Data Warehouse - so not the regular RDBMS product.
请注意,Microsoft 在 SQL 2012 中向 TSQL 语法添加了 EXPLAIN 命令,但它仅适用于 Azure SQL 数据仓库和并行数据仓库 - 因此不适用于常规 RDBMS 产品。
It provides an execution plan in XML format, and helpfully shows the parts of the plan that will be distributed across the warehouse nodes.
它提供了一个 XML 格式的执行计划,并有助于显示将在仓库节点之间分布的计划部分。
Source: TSQL EXPLAIN
来源: TSQL 解释
回答by Micha? Lepczyński
In SSMS (I got 18.3.1) highlight the query in question and hit CTRL+L
在 SSMS(我得到 18.3.1)中突出显示有问题的查询并点击CTRL+L
(that does what Tobias mentioned - Query->Display Estimated Query Plan
)
(这就是托比亚斯提到的 - Query->Display Estimated Query Plan
)
回答by HLGEM
You need to look at the Execution plan in SQl Server. Look up the term in books online for how to use it.
您需要查看 SQL Server 中的执行计划。在在线书籍中查找该术语以了解如何使用它。
They are not so simple to read, you might want to do some ressearch, here's a google search term to get you started:
它们不是那么容易阅读,您可能需要进行一些研究,这是一个可以帮助您入门的谷歌搜索词:
reading execution plan sql server
读取执行计划sql server