Lesson 1 of 3 Query Performance Analysis

Reading Execution Plans

This lesson explains estimated and actual plans, the operators and warnings to look for, and how statistics influence plan quality.

Learning outcomes

After completing this lesson, you will be able to:

  • Distinguish between estimated and actual execution plans.
  • Identify common plan warnings and their causes.
  • Explain how statistics and implicit conversions affect plans.

Estimated and actual plans

The query optimizer chooses a plan by estimating the cost of alternatives from statistics about the data. An estimated plan shows the chosen plan without running the query. An actual plan runs the query and adds runtime information: actual rows per operator, executions, memory grants and waits. Comparing estimated rows with actual rows is the most useful check, because large differences mean the optimizer chose the plan with wrong assumptions, for example a nested loops join for what turned out to be millions of rows. Plans are viewed in SSMS, in the MSSQL extension for VS Code and from the plan columns of DMVs and Query Store.

True or false

Estimated and actual plans

Exam skills 2.2.3

Decide whether each statement about execution plans is true.

Log in to try this activity Interactive activities are free with an account.

Operators and warnings

Common operators and what they suggest are summarized in the following table.

Plan elementWhat it suggests
Index seekEfficient access to a range of rows through an index
Index or table scanReading everything: fine for small tables or large results, a problem for selective queries
Key lookupA nonclustered index lacks columns; consider INCLUDE
Hash match and sort spills (warning)The memory grant was too small, often due to underestimated rows
Implicit conversion (warning)A data type mismatch that can prevent seeks
Missing index suggestionA candidate index; evaluate before creating it
Parallelism operatorsThe query ran in parallel; check for skew or unnecessary parallelism
Match the pairs

Reading plan elements

Exam skills 2.2.3

Match each plan element with what it suggests.

Log in to try this activity Interactive activities are free with an account.

Statistics and plan quality

Statistics describe the distribution of values in columns and indexes. They are created and updated automatically, but large tables can have stale statistics until enough rows change, and ascending keys such as dates can be underestimated for recent values. UPDATE STATISTICS with a larger sample, filtered statistics and, for skewed parameters, the remedies for parameter sniffing improve estimates. SET STATISTICS IO, TIME ON shows logical reads and CPU time per statement, which measures the effect of a change better than elapsed time on a shared system.

SET STATISTICS IO, TIME ON;
SELECT OrderID, TotalDue FROM Sales.Orders WHERE CustomerID = 4711 AND OrderDate >= '2026-01-01';
-- Messages: logical reads per table and CPU time

UPDATE STATISTICS Sales.Orders WITH FULLSCAN;
Scenario questions

Statistics

Exam skills 2.2.3 · 2.2.4

Choose the explanation or fix for each statistics problem.

Log in to try this activity Interactive activities are free with an account.
Worked example

An index that is not used

A query filters WHERE AccountNumber = @acct, where AccountNumber is varchar(20) with a nonclustered index. The application passes the parameter as nvarchar(4000). The plan shows an index scan with an implicit conversion warning. What should the developer fix?

Make the parameter type match the column, varchar(20), in the application or procedure. Because nvarchar has higher precedence, the column is converted on every row, which turns the seek into a scan. Rebuilding the index or updating statistics will not remove the conversion, and an index hint would force the index but still convert every row.

Check yourself

What does a large gap between estimated and actual rows suggest?

Show answer

The optimizer chose the plan with wrong assumptions, typically stale statistics or parameter sensitivity.

Exam Tips

Remember for the exam

  • Compare estimated and actual rows to find bad estimates.
  • Key lookups: cover the query with INCLUDE columns.
  • Implicit conversion warnings: match parameter and column types.
  • Measure with STATISTICS IO and TIME; logical reads are a stable metric.