显示实际执行计划Display an Actual Execution Plan

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 是Azure SQL 数据库Azure SQL DatabaseYesAzure SQL 数据库Azure SQL Database

本主题介绍了如何使用 SQL Server Management StudioSQL Server Management Studio生成实际的图形化执行计划。This topic describes how to generate actual graphical execution plans by using SQL Server Management StudioSQL Server Management Studio. 执行 Transact-SQLTransact-SQL 查询或批处理后,将生成实际的执行计划。Actual execution plans are generated after the Transact-SQLTransact-SQL queries or batches execute. 为此,实际的执行计划包含运行时信息,例如实际的资源使用量度量值和运行时警告(如果有)。Because of this, an actual execution plan contains runtime information, such as actual resource usage metrics and runtime warnings (if any). 生成的执行计划会显示 SQL Server 数据库引擎SQL Server Database Engine 用于执行查询的实际查询执行计划。The execution plan that is generated displays the actual query execution plan that the SQL Server 数据库引擎SQL Server Database Engine used to execute the queries.

若要使用此功能,用户必须具有相应权限来执行要为其生成图形化执行计划的 Transact-SQLTransact-SQL 查询,并且对于查询所引用的所有数据库,用户必须被授予 SHOWPLAN 权限。To use this feature, users must have the appropriate permissions to execute the Transact-SQLTransact-SQL queries for which a graphical execution plan is being generated, and they must be granted the SHOWPLAN permission for all databases referenced by the query.

在查询执行中包括其执行计划To include an execution plan for a query during execution

  1. SQL Server Management StudioSQL Server Management Studio 工具栏中,单击 “数据库引擎查询”On the SQL Server Management StudioSQL Server Management Studio toolbar, click Database Engine Query. 通过单击 “打开文件” 工具栏按钮,再定位到该现有查询,也可以打开一个现有查询并显示估计的执行计划。You can also open an existing query and display the estimated execution plan by clicking the Open File toolbar button and locating the existing query.

  2. 输入要显示其实际执行计划的查询。Enter the query for which you would like to display the actual execution plan.

  3. 在“查询”菜单中,单击“包括实际的执行计划”或单击“包括实际的执行计划”工具栏按钮 。On the Query menu, click Include Actual Execution Plan or click the Include Actual Execution Plan toolbar button.

    工具栏上的“实际执行计划”按钮Actual Execution Plan button on toolbar

  4. 通过单击 “执行” 工具栏按钮执行查询。Execute the query by clicking the Execute toolbar button. 查询优化器使用的计划将显示在结果窗格的 “执行计划” 选项卡中。The plan used by the query optimizer is displayed on the Execution Plan tab in the results pane.

    实际执行计划Actual Execution Plan

  5. 将鼠标悬停在逻辑和物理运算符上,通过选择根节点运算符(上图中的 SELECT 节点),在显示的工具提示中查看运算符的描述和属性,包括整个执行计划的属性。Pause the mouse over the logical and physical operators to view the description and properties of the operators in the displayed ToolTip, including properties of the overall execution plan, by selecting the root node operator (the SELECT node in the picture above).

    另外,还可以在“属性”窗口中查看运算符属性。Alternatively, you can view operator properties in the Properties window. 如果属性不可见,请右键单击一个运算符并单击“属性”。If Properties is not visible, right-click an operator and click Properties. 选择要查看其属性的运算符。Select an operator to view its properties.

    右键单击计划运算符中的“属性”Right-click Properties in plan operator

  6. 可以通过右键单击执行计划并选择“放大”、“缩小”、“自定义显示比例”或“缩放到合适大小”来更改执行计划的显示。 You can alter the display of the execution plan by right-clicking the execution plan and selecting Zoom In, Zoom Out, Custom Zoom, or Zoom to Fit. “放大”“缩小” 可以放大或缩小执行计划, “自定义显示比例” 使您可以定义自己需要的显示比例,例如缩放到 80%。Zoom In and Zoom Out allow you to zoom in or out on the execution plan, while Custom Zoom allows you to define your own zoom, such as zooming at 80 percent. “缩放到合适大小” 会放大执行计划以适应结果窗格。Zoom to Fit magnifies the execution plan to fit the result pane. 或者,使用 Ctrl 键和鼠标滚轮的组合来激活动态缩放。Alternatively, use a combination of the CTRL key and your mouse wheel to activate dynamic zoom.

  7. 若要导航执行计划的显示,请使用垂直和水平滚动条,或单击并按住执行计划的任何空白区域,然后拖动鼠标 。To navigate the display of the execution plan, use the vertical and horizontal scroll bars, or click and hold on any blank area of the execution plan, and drag your mouse. 或者,在右下角的执行计划窗口中单击并按住加号 (+),以显示整个执行计划的缩略图。Alternatively, click and hold the plus (+) sign in the right lower corner of the execution plan window, to display a miniature map of the entire execution plan.

备注

或者,使用 SET STATISTICS XML 在执行每条语句后返回该语句的执行计划信息。Alternatively, use SET STATISTICS XML to return execution plan information for each statement after executing it. 如果在 SQL Server Management StudioSQL Server Management Studio 中使用,“结果”选项卡中将包含用于以图形格式打开执行计划的链接。If used in SQL Server Management StudioSQL Server Management Studio, the Results tab will have a link to open the execution plan in graphical format.
有关详细信息,请参阅查询分析基础结构For more information, see Query Profiling Infrastructure.

另请参阅See Also

执行计划 Execution Plans
查询处理体系结构指南Query Processing Architecture Guide