SQL Server查询执行计划–查看计划

本文详细介绍了在SQL Server中查看查询执行计划的各种方法,包括使用ApexSQL Plan、SHOWPLAN_XML、查询缓存、STATISTICS选项以及SQL Server Profiler。实际执行计划提供更准确的数据,而估计执行计划则用于无实际运行情况下的分析。通过这些方法,开发者可以进行性能分析和故障排查。

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

In the SQL Server query execution plans – Basics, we described the query execution plans in SQL Server and why they are important for performance analysis. In this article, we will focus on the methods for opening the plans, both actual and estimated ones

在“ SQL Server查询执行计划-基础知识”中 ,我们描述了SQL Server中的查询执行计划以及为什么它们对性能分析很重要。 在本文中,我们将重点介绍开放计划的方法,包括实际的和估计的方法。

If you look at the Query item in the SQL Server Management Studio menu, you’ll see two options related to query plans – Display Estimated Execution plan and Include Actual Execution plan

如果您查看SQL Server Management Studio菜单中的“ 查询”项,您将看到与查询计划相关的两个选项-“ 显示估计的执行计划”和“ 包括实际的执行计划”

An estimated execution plan is a SQL Server query plan that is generated without actually running the query (or stored procedure) the plan is created for. It’s based on estimation of expected behavior. It’s useful for analyzing how a query would behave, without actually running it. This is very useful for testing purposes in environments where performance should not be affected by running actual code (e.g. running a SELECT statement with complex joins against huge tables), or when running code is not possible due to data changes it makes (e.g. executing an UPDATE). Its downside is that it might be inaccurate in some scenarios

估计执行计划是一种SQL Server查询计划,该计划是在不实际运行为其创建查询的查询(或存储过程)的情况下生成的。 它基于对预期行为的估计。 这对于分析查询的行为很有用,而无需实际运行它。 这对于在以下环境中进行测试的目的非常有用:在这些环境中,运行实际代码不会影响性能(例如,对大型表运行带有复杂联接的SELECT语句),或者由于数据更改而无法运行代码(例如,执行更新)。 它的缺点是在某些情况下可能不准确

An actual execution plan is the SQL Server query plan that is generated after a query was executed. It’s more reliable, as it’s based on the actual execution, not estimates. It also provides more information and statistics, therefore it’s much useful in troubleshooting

实际的执行计划是在执行查询后生成SQL Server查询计划。 它更可靠,因为它基于实际执行,而不是估计。 它还提供更多的信息和统计信息,因此在故障排除中非常有用

There are several methods available for viewing a query plan in SQL Server

有几种方法可用于查看SQL Server中的查询计划

使用ApexSQL计划查看实际执行计划 (View Actual execution plan using ApexSQL Plan)

The Actual execution plan option is available in the in the Home tab of ApexSQL Plan

ApexSQL Plan的“主页”选项卡中的“ 实际执行计划”选项可用

  1. Query in ApexSQL Plan查询
  2. Actual execution plan option实际执行计划选项


SELECT *
  FROM person.PersonPhone
  WHERE PhoneNumber LIKE '%697%'

If multiple SQL queries are e

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值