What an execution plan is for

We write a query to state the result we need. SQL Server must still decide how to locate, combine, and process the data that produces it. The execution plan represents that strategy.

Path from a query to measurements collected during execution

The query describes the result

SQL is a declarative language: we express the result we want, not a complete sequence of physical steps. A statement can request customers with confirmed orders without specifying which index to open first, how to traverse it, or which method should relate the tables.

Declarative means that we describe the objective. The engine remains responsible for choosing a strategy to reach it.

Two queries can return the same rows through different strategies. The same query can also receive another plan when its parameters, data, indexes, statistics, or engine version change.

The optimizer chooses a strategy

Before executing a query, SQL Server uses the optimizer to compare alternatives. This component considers the available structures and estimates the work required by different paths.

Those structures can include tables, indexes, and statistics:

  • a table stores rows and columns;
  • an index organizes values to support particular access methods;
  • statistics describe the approximate distribution of data and help estimate how many rows may satisfy a condition.

The optimizer does not try every possible strategy. It searches for an alternative with a reasonable estimated cost within the time available for compilation.

The plan represents the selected strategy

Actual execution plan displayed by SQL Server Management Studio

An execution plan represents the operations SQL Server chose to connect in order to produce the result. Each operation receives, obtains, or returns rows.

These operations are called operators. An operator can access a table or index, filter rows, combine sets, sort data, or calculate a value. The plan shows how they relate, but we still need to learn its structure before deciding whether a choice deserves investigation.

Result, strategy, and measurement

It helps to keep three elements separate:

  • the result contains the rows produced by the query;
  • the plan describes the strategy selected to obtain them;
  • measurements record observed work such as reads, CPU, or duration.

A correct result does not prove that the strategy is suitable for every volume or parameter. A plan also does not prove by itself how long an execution took. Evaluating performance requires relating the strategy to measurements captured under known conditions.

What the plan helps us investigate

The plan helps us:

  • reconstruct how SQL Server expects to access and process the data;
  • recognize the tables, indexes, and operations involved;
  • locate estimates or choices that need verification;
  • compare strategies before and after a controlled change;
  • formulate a more precise question about the work performed by a query.

What it does not prove yet

An isolated plan does not prove that an operation is wrong, that an index must be created, or that the alternative with the lower estimated cost will perform better under every condition.

It also does not justify changing a business query without reviewing parameters, frequency, volume, concurrency, and effects on other operations. The plan contributes evidence for an investigation; it does not replace measurement or context.

Reasonable next check

The next article distinguishes estimated plans, actual plans, and Live Query Statistics. After that, we will study the anatomy of the diagram before working with controlled examples.

Path index

Execution plans

30 articles in Execution plans
  1. 01What an execution plan is for
  2. 02Estimated plans, actual plans, and Live Query Statistics
  3. 03How an execution plan tree is organized
  4. 04Arrows, properties, and execution counts
  5. 05Operator map: what role each node plays
  6. 06Estimated rows and actual rows
  7. 07Index Seek, Index Scan, and Table Scan
  8. 08Key Lookup and repeated work
  9. 09Filter, Compute Scalar, and Top
  10. 10Nested Loops, Hash Match, and Merge Join
  11. 11Sort, Segment, and Sequence Project
  12. 12Stream Aggregate and Hash Match Aggregate
  13. 13Spool: materialization and reuse
  14. 14Parallelism: distributing, repartitioning, and gathering rows
  15. 15Execution plan warnings that require investigation
  16. 16Actions available in the SSMS graphical plan
  17. 17How Showplan XML is organized
  18. 18Walk through Analyze Actual Execution Plan
  19. 19Reads with SET STATISTICS IO
  20. 20CPU and elapsed time with SET STATISTICS TIME
  21. 21Build a repeatable baseline
  22. 22Save and compare two plans
  23. 23History and regressions with Query Store
  24. 24Turn an Analyze Actual Execution Plan scenario into a hypothesis
  25. 25Read a Missing Index suggestion in an execution plan
  26. 26Understand the CREATE INDEX generated by SSMS
  27. 27Decide, create, and verify an index
  28. 28From a slow query to a testable hypothesis
  29. 29Evaluate a change without optimizing for one execution
  30. 30Guided analysis of a reproducible business query