What is an Execution Plan?
An execution plan shows how SQL Server executes a query and retrieves the requested data.
It displays operations such as:
-
Table scan or index scan
-
Index seek
-
Joins
-
Sorting and filtering
-
Key lookups
-
Estimated number of rows
-
Cost of each operation
Types
-
Estimated Execution Plan: Shows the expected execution method without running the query.
-
Actual Execution Plan: Runs the query and includes real execution details, such as actual rows processed.
Why is it useful?
It helps identify performance problems such as:
-
Full-table scans
-
Missing or inefficient indexes
-
Expensive joins and key lookups
-
Incorrect row estimates
-
Sort or hash spills
-
Implicit conversions
Example
SELECT *
FROM Employees
WHERE DepartmentId = 10;
The plan may show an Index Seek if a suitable index exists, or a Table Scan if it does not.
Key point
An execution plan is the primary tool for understanding and troubleshooting SQL query performance. Always examine the actual execution plan when possible.