Displaying an Actual Execution Plan in SQL Server Management Studio

Understanding how SQL Server executes your queries is crucial for performance tuning. An Actual Execution Plan shows you what SQL Server did to run your query, including the steps taken, the cost of each step, and the number of rows processed.

This guide will walk you through the process of generating and interpreting an actual execution plan using SQL Server Management Studio (SSMS).

Why Use an Actual Execution Plan?

Steps to Display an Actual Execution Plan

Step 1: Open SQL Server Management Studio (SSMS)

Connect to your SQL Server instance.

Step 2: Open a New Query Window

Click on the New Query button in the SSMS toolbar or press Ctrl+N.

Step 3: Write Your SQL Query

Enter the SQL query you want to analyze. For demonstration purposes, let's use a simple query:


SELECT
    CustomerID,
    FirstName,
    LastName,
    EmailAddress
FROM
    Sales.Customer
WHERE
    TerritoryID = 5
ORDER BY
    LastName;
                

Step 4: Enable "Include Actual Execution Plan"

There are two primary ways to do this:

  • Toolbar Button: Click the Display Estimated Execution Plan button in the query toolbar. This button often looks like a small flowchart. Hovering over it will show "Include Actual Execution Plan" in the tooltip. Clicking it toggles the setting.

    Alternatively, you can find the option under the Query menu: Query > Include Actual Execution Plan.

  • Keyboard Shortcut: Press Ctrl+M. This is a quick toggle to enable/disable including the actual execution plan.

When enabled, the button will appear pressed, and you'll see a tab labeled Execution plan appear in the results pane before you execute the query. If you've already executed a query with the plan included, the tab will be there.

Step 5: Execute Your Query

Click the Execute button in the toolbar or press F5.

Step 6: View the Actual Execution Plan

After the query completes, a new tab titled Execution plan will appear in the results pane. This tab displays the graphical representation of the actual execution plan.

Important: The actual execution plan is generated *after* the query has run. The estimated execution plan, generated *before* running the query, is useful for initial analysis but may differ significantly from the actual plan.

Interpreting the Execution Plan

The execution plan is a visual flowchart where each icon represents an operation (e.g., Table Scan, Index Seek, Sort, Hash Match). The arrows indicate the flow of data between operations, with the thickness of the arrow representing the number of rows flowing.

Key Elements to Look For:

Example Scenario:

If you see a Clustered Index Scan on a large table and your query is filtering on a specific column, it's a strong indicator that an index on that column would significantly improve performance.

This graphical representation is interactive. You can zoom, pan, and click on individual operators to see their properties in the Properties window (press F4 if it's not visible).

Conclusion

Mastering the interpretation of actual execution plans is a fundamental skill for any SQL Server developer or administrator. By understanding how your queries are being executed, you can effectively identify performance bottlenecks and optimize your database for better efficiency.