SQL Server相当于MySQL的EXPLAIN
我正在阅读一个 SQL 教程,其中使用关键字 EXPLAIN 来查看查询是如何执行的。我在 SQL Server 2008 中尝试过,但没有成功。
我怎样才能得到同等的结果?
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.
How do I get the equivalent result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MySql EXPLAIN 语句可以用作 DESCRIBE 的同义词,也可以用作一种方式获取有关 MySQL 如何执行 SELECT 语句的信息。
SQL Server 最接近的等效语句是:
SET SHOWPLAN_ALL (Transact-SQL)
或
SET SHOWPLAN_XML (Transact-SQL)
从 SQL Server Management Studio 查询窗口,您可以运行
SET SHOWPLAN_ALL ON
或SET SHOWPLAN_XML ON
然后运行您的查询。此时它不会返回查询的结果集,而是实际的执行计划。当您运行SET SHOWPLAN_ALL OFF
或SET SHOWPLAN_XML OFF
并运行查询时,您将再次获得结果集。The MySql EXPLAIN statement can be used either as a synonym for DESCRIBE or as a way to obtain information about how MySQL executes a SELECT statement.
The closest equivalent statement for SQL Server is:
SET SHOWPLAN_ALL (Transact-SQL)
or
SET SHOWPLAN_XML (Transact-SQL)
From a SQL Server Management Studio query window, you could run
SET SHOWPLAN_ALL ON
orSET 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 runSET SHOWPLAN_ALL OFF
orSET SHOWPLAN_XML OFF
and then run your query, you will then again get a result set.我相信
EXPLAIN
关键字是一个 MySQL 概念 - 等效的 Microsoft SQL Server 概念是执行计划。获取执行计划的最简单方法是在 SQL Server Management Studio 中打开“显示实际执行计划”菜单项(在查询菜单中)。或者,您可以在此处阅读有关执行计划的更深入指南:
本文更详细地介绍了什么是执行计划、如何获取执行计划以及不同的执行计划格式。
I believe that the
EXPLAIN
keyword is an MySQL concept - the equivalent Microsoft SQL server concept is the execution plan.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:
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.
在 SSMS(我得到 18.3.1)中突出显示有问题的查询并点击 CTRL+L
(这就是 Tobias 提到的 -
Query->Display Estimated Query计划
)In SSMS (I got 18.3.1) highlight the query in question and hit CTRL+L
(that does what Tobias mentioned -
Query->Display Estimated Query Plan
)请注意,Microsoft 在 SQL 2012 中向 TSQL 语法添加了 EXPLAIN 命令,但它仅适用于 Azure SQL 数据仓库和并行数据仓库 - 因此不适用于常规 RDBMS 产品。
它提供 XML 格式的执行计划,并有助于显示将分布在仓库节点上的计划部分。
来源:
TSQL EXPLAIN
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.
It provides an execution plan in XML format, and helpfully shows the parts of the plan that will be distributed across the warehouse nodes.
Source:
TSQL EXPLAIN