Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Execution Plans

Execution plans are the roadmap that SQL Server uses to retrieve data. Understanding how to read and analyze execution plans is crucial for performance tuning.

Topics

Overview

An execution plan shows how SQL Server will execute a query, including:

  • Which indexes are used
  • Join methods
  • Scan types (table scan vs index scan/seek)
  • Sort operations
  • And various other operators

Why Execution Plans Matter

  • Performance Tuning: Identify bottlenecks in queries
  • Index Analysis: Understand if indexes are being used effectively
  • Query Optimization: See why a query is slow and how to improve it
  • Cardinality Estimates: Understand row count predictions

How to View Execution Plans

Using SSMS (SQL Server Management Studio)

  1. Enable “Include Actual Execution Plan” (Ctrl + M)
  2. Run your query
  3. View the Execution Plan tab

Using T-SQL

SET STATISTICS XML ON;
-- Your query here
SET STATISTICS XML OFF;

Common Operators

OperatorDescription
Table ScanReads all rows from a table
Index ScanReads all entries from an index
Index SeekUses index to find specific rows
Clustered Index ScanScans entire clustered index (entire table)
Nested LoopsJoins using nested iteration
Hash JoinJoins using hash table
Merge JoinJoins using sorted inputs
Compute ScalarCalculates new values from existing data
SortOrders data
FilterFilters rows based on condition

Further Reading

For detailed information about specific operators, see the topics in this section.