在Azure Data Studio中查看执行计划

本文详细介绍了如何在Azure Data Studio中查看查询的估计和实际执行计划。通过图形化和XML格式,数据库管理员可以更好地分析和解决查询性能问题。文章还提到了Azure Data Studio的其他功能,如查看最耗时的操作,以及使用`Run Current Query with Actual Plan`命令获取实际执行计划。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This article gives an overview of viewing execution plans in the Azure Data Studio.

本文概述了在Azure Data Studio中查看执行计划。

介绍 (Introduction)

Database administrators use a query execution plan for troubleshooting query performance issues. Suppose one day a user calls you and says my query is running slow. You might perform several checks such as blocking, deadlock, CPU, memory, IO utilization, waits etc. You can also capture the query execution plan to check the overall flow of the query internally. You get detailed information in the plan.

数据库管理员使用查询执行计划来解决查询性能问题。 假设某天某用户打电话给您,并说我的查询运行缓慢。 您可能会执行一些检查,例如阻塞,死锁,CPU,内存,IO利用率,等待等。您还可以捕获查询执行计划,以在内部检查查询的总体流程。 您将在计划中获得详细信息。

We can get two formats of a query execution plan:

我们可以获得查询执行计划的两种格式:

  • Graphical: it gives a graphical representation of all operators, their properties, tooltip information. We can interpret results quickly in a graphical format

    图形化:它以图形方式表示所有操作员,其属性和工具提示信息。 我们可以以图形格式快速解释结果

    Graphical Execution Plan

  • XML format: It shows a query plan in an XML format. It gives detailed information, but you should be an experienced DBA to understand it

    XML格式:它以XML格式显示查询计划。 它提供了详细的信息,但是您应该是有经验的DBA才能理解它

    XML format plan

You can check out the following articles to get a detailed knowledge of execution plans.

您可以查看以下文章以获得执行计划的详细知识。

SQL Server provides the following types of query plans:

SQL Server提供以下类型的查询计划:

  • Estimated execution plan: SQL Server generates the query plan without actually executing the query 估计执行计划 :SQL Server生成查询计划,而无需实际执行查询
  • Actual execution plan: It is an actual representation of a query plan that SQL Server generates by executing the query 实际执行计划:这是SQL Server通过执行查询生成的查询计划的实际表示。

You can go through SQL Server Execution Plans types for comparison of an estimated and actual query plan. Usually, DBA uses SQL Server Management Studio or third-party tools such as ApexSQL Plan to check query plans.

您可以浏览SQL Server执行计划类型,以比较估计的查询计划和实际的查询计划。 通常,DBA使用SQL Server Management Studio或第三方工具(例如ApexSQL Plan)来检查查询计划。

Azure Data Studio is a new tool from Microsoft that you can install on Linux as well. It also provides several useful features such as code snippets, Integrated terminals (SSH and PowerShell), extensions, query charts, various results format, server dashboard. SQLShack has many useful articles for Azure Data Studio.

Azure Data Studio是Microsoft的新工具,也可以在Linux上安装。 它还提供了一些有用的功能,例如代码段,集成终端(SSH和PowerShell),扩展,查询图表,各种结果格式,服务器仪表板。 SQLShack有许多有关Azure Data Studio的有用文章。

Suppose you are using Azure Data Studio and you need to view both estimated and actual query plans. Do we have a way to check a query plan in ADS? Does it provide any additional features in comparison with SSMS plans? Let’s check it out.

假设您正在使用Azure Data Studio,并且需要查看估计和实际查询计划。 我们是否可以检查ADS中的查询计划? 与SSMS计划相比,它是否提供任何其他功能? 让我们来看看。

You should install Azure Data Studio’s latest release before going through this article. Launch URL, choose your platform and download installer. You can also use the Windows user installer (recommended) because it does not require a user with administrative rights.

在阅读本文之前,您应该安装Azure Data Studio的最新版本。 启动URL ,选择您的平台并下载安装程序。 您也可以使用Windows用户安装程序(推荐),因为它不需要具有管理权限的用户。

Azure Data Studio

Launch ADS and connect to a SQL Server instance. In this article, I am using the [AdventureWorks] sample database.

启动ADS并连接到SQL Server实例。 在本文中,我正在使用[AdventureWorks]示例数据库。

Expand the database and right-click on [HumanResources].[vEmployee] view to select the top 1000 rows using the highlighted option below.

展开数据库,然后右键单击[HumanResources]。[vEmployee]视图,使用下面的突出显示的选项选择前1000行。

SELECT TOP 1000 rows

It executes the query, and you get results in a grid format, as shown below.

它执行查询,并以网格格式获得结果,如下所示。

Results tab

In the Query menu, click on the Explain option at the top of the query window.

在查询菜单中,单击查询窗口顶部的解释选项。

Explain button

Click on the Explain, and it shows the execution plan in a Query Plan tab.

单击“ 说明”,它会在“ 查询计划”选项卡中显示执行计划。

Query Plan tab

We get an estimated execution plan in graphical format using this Explain option. You do not see query results (output) because SQL Server does not execute the query in the estimated query plan. If we want to see the XML query plan, we can get it from the Result tab.

使用此Explain选项,我们可以获得图形格式的估计执行计划。 您看不到查询结果(输出),因为SQL Server不在估计的查询计划中执行查询。 如果要查看XML查询计划,可以从“ 结果”选项卡中获取它。

XML query plan in Result tab

To view completed XML plan, click on the XML and you get the full XML view with a beautiful color coding.

View completed XML

要查看完整的XML计划,请单击XML,您将获得完整的XML视图以及漂亮的颜色编码。

We can save this XML plan with a *.sqlplan extension for future usage. To save this plan, go to File-> Save As.

我们可以使用* .sqlplan扩展名保存此XML计划,以备将来使用。 要保存该计划,请转到“文件”->“另存为”。

Specify a file name with *.sqlplan extension in a required directory.

在所需目录中指定带有* .sqlplan扩展名的文件名。

Save Query plan

Once you save the execution plan, it opens the following graphical format. We cannot get the top operators from this saved plan.

保存执行计划后,它将打开以下图形格式。 我们无法从此保存的计划中获取顶级操作员。

View saved plan

You should read a graphical execution plan from right to left direction because data flow happens in that direction. You can go through the article How to Analyze SQL Execution Plan Graphical Components to understand it in a detailed manner.

您应该从右到左阅读图形执行计划,因为数据流是在那个方向发生的。 您可以阅读文章“ 如何分析SQL执行计划图形组件”以详细了解它。

For a long query, we might see a complicated execution plan with a large window. You might face difficulty to analyze the costly operators associated with the query. Azure Data Studio provides a solution for this as well. You see an additional tab Top Operations to check all operators and their costs in a tabular format.

对于较长的查询,我们可能会看到一个带有大窗口的复杂执行计划。 您可能难以分析与查询关联的昂贵运算符。 Azure Data Studio也为此提供了一个解决方案。 您会看到一个附加的顶部操作选项卡,以表格形式检查所有操作员及其费用。

Click on the Top Operations, and you get the following output.

单击“ 主要操作”,您将获得以下输出。

TOP Operations

It is an interactive window to check the operators. You can click on any column and sort the output in a descending or ascending order.

它是检查操作员的交互式窗口。 您可以单击任何列,然后按降序或升序对输出进行排序。

For example, if we want to sort this table based on estimated rows flowing through each operator. Click on the Est Rows column, and it sorts results accordingly.

例如,如果我们要基于流经每个运算符的估计行对该表进行排序。 单击“ 估计行”列,然后对结果进行排序。

Click on the Est Rows column

Similarly, we can sort results according to the Est Costs of plan operators.

同样,我们可以根据计划运营商的估计成本对结果进行排序。

View sorted result

It is an excellent way to identify the costly operators taking most of the resources and time. You can go back to the graphical plan to check more details around that identified operator.

这是一种识别占用大量资源和时间的昂贵运营商的绝佳方法。 您可以返回图形化计划,以检查有关该已识别操作员的更多详细信息。

在Azure Data Studio中获取实际的执行计划 (Get Actual Execution Plan in Azure Data Studio)

As we see earlier, the Explain option gives you an estimated query plan. In most cases, we prefer to get the actual execution plan and investigate it further. I would recommend to use the actual execution plan as well so that you can get an idea of what caused the query to behave slowly.

正如我们前面所看到的,“ 解释”选项为您提供了一个估计的查询计划。 在大多数情况下,我们倾向于获取实际的执行计划并进行进一步调查。 我建议也使用实际的执行计划,以便您了解导致查询运行缓慢的原因。

To get an actual query plan, first, write the query in a new query window and then go to View -> Command Palette.

要获取实际的查询计划,请首先在新的查询窗口中编写查询,然后转到“ 视图”->“命令面板”。

It opens the list of available commands, as shown below.

它将打开可用命令的列表,如下所示。

View Command Palette

Type Run Current Query with Actual Plan and click on the highlighted option.

键入运行带有实际计划的当前查询 单击突出显示的选项。

Run Current Query with Actual Plan

You can use keyboard shortcut CTRL+M to execute the query and get an actual execution plan, as shown below.

您可以使用键盘快捷键CTRL + M来执行查询并获取实际的执行计划,如下所示。

Keyboard shortcut CTRL+M

You get similar options as of the estimated query plan. In the result pane, you get the query result as well as the XML query plan in Azure Data Studio.

您将获得与估计查询计划相似的选项。 在结果窗格中,您将获得查询结果以及Azure Data Studio中的XML查询计划。

XML query plan

结论 (Conclusion)

In this article, we explored ways to view the estimated and actual execution plans in the Azure data studio. We also viewed ways to get graphical and XML plan using this ADS.

在本文中,我们探索了在Azure数据工作室中查看估计和实际执行计划的方法。 我们还查看了使用此ADS获取图形和XML计划的方法。

翻译自: https://www.sqlshack.com/view-execution-plans-in-azure-data-studio/

### 回答1: 要在Azure Data Studio中设置中文,您可以按照以下步骤操作: 1. 打开Azure Data Studio 2. 点击左侧导航栏中的“设置”按钮 3. 在“设置”页面中,选择“语言”选项卡 4. 在“语言”选项卡中,选择“中文(简体)”或“中文(繁体)”作为首选语言 5. 关闭并重新打开Azure Data Studio,以使更改生效 这样,您就可以在Azure Data Studio中使用中文了。 ### 回答2: Azure Data Studio是微软推出的跨平台数据库工具,将SQL Server Management Studio (SSMS)和Visual Studio Code相结合,提供了更加灵活、高效的数据管理和开发体验。在Azure Data Studio中设置中文比较简单,只需要按照以下步骤进行操作即可。 1. 下载安装Azure Data Studio 首先需要在官网或微软商店下载安装Azure Data Studio,安装过程类似其他软件的安装,不再赘述。如果已经安装了Azure Data Studio,则可以直接跳过此步骤。 2. 安装语言包 安装程序默认是英文界面,如果要设置为中文,需要下载并安装中文语言包。中文语言包可以在Azure Data Studio的官网上下载,也可以在扩展商店中搜索Azure Data Studio Language Pack并进行安装。安装完成后,需要重启Azure Data Studio才能生效。 3. 修改语言设置 打开Azure Data Studio之后,选择左上角的“文件”菜单,选择“首选项”选项。在弹出的选项页面左侧选择“用户设置”,在右侧页面的搜索框中输入“locale”,找到“Azure Data Studio: Preferred Language”选项,并将其设置为“zh-cn”。此时,Azure Data Studio会以中文显示。 总之,设置Azure Data Studio为中文非常简单,只需要下载安装语言包并修改设置即可。希望这篇回答能够帮助到需要的人。 ### 回答3: Azure Data Studio是一款跨平台的数据库工具,支持许多不同的数据库,如SQL Server、PostgreSQL和MySQL等。虽然该软件默认是英文界面,但是可以很容易地将其切换为中文界面。 要设置Azure Data Studio的语言为中文,需要按照以下步骤进行操作: 1. 下载并安装最新版本的Azure Data Studio。可以从官方网站https://docs.microsoft.com/en-us/sql/azure-data-studio/download选择适合自己操作系统的版本进行下载。 2. 安装后,启动Azure Data Studio。 3. 选择“文件”菜单,在下拉列表中选择“首选项”。 4. 在弹出的窗口中,选择“用户设置”。 5. 在用户设置的JSON文件中,添加以下内容: "locale": "zh-cn" 注意,这里设置的是以“zh-cn”为代表的中文简体语言,如果需要使用其他语言,可以将“zh-cn”替换为其他语言的标识。 6. 保存并关闭用户设置文件。 7. 重启Azure Data Studio,可以看到软件界面已经是中文。 以上就是将Azure Data Studio设置为中文的步骤,只要按照以上步骤操作,就可以轻松切换软件的语言界面了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值