Microsoft Fabric  

Understanding SHOWPLAN_ALL in SQL Server and Microsoft Fabric

As data engineers, we spend a significant amount of time writing SQL queries to ingest, transform, and analyze data. However, producing the correct result is only half the story. Equally important is understanding how the SQL Server Query Optimizer executes our queries.

One of the most effective ways to inspect the optimizer's decisions is by using SHOWPLAN_ALL.

In this article, I'll demonstrate how to use SHOWPLAN_ALL in SQL Server and Microsoft Fabric SQL Database, explain what it does, discuss a common pitfall, and show you how to resolve it.

What is SHOWPLAN_ALL?

SHOWPLAN_ALL is a session-level SQL Server setting that instructs the query optimizer to return the estimated execution plan instead of executing the query.

Rather than returning data, SQL Server provides detailed information about the physical operators it intends to use, allowing us to understand how the query will be processed before it runs.

This is particularly useful when:

  • Investigating slow-running queries.

  • Understanding optimizer decisions.

  • Identifying expensive operations such as sorts and scans.

  • Comparing different query implementations.

  • Tuning SQL for better performance.

Unlike PostgreSQL, MySQL, Oracle, or Databricks SQL, which support variations of the EXPLAIN command, SQL Server relies on SHOWPLAN_ALL and graphical execution plans.

Orders Table

For this walkthrough, I'll use anorders table in Fabric SQL

CREATE TABLE orders
(
    order_id INT PRIMARY KEY NOT NULL,
    order_date DATE NOT NULL,
    customer VARCHAR(20) NOT NULL,
    amount INT NOT NULL
);

After populating the table with data, I'll calculate a running total using a window function.

1

Sample Query

SELECT
    order_id,
    order_date,
    customer,
    amount,
    SUM(amount) OVER
    (
        ORDER BY order_date, order_id
    ) AS running_total
FROM orders
ORDER BY customer, order_date, order_id;

Without any execution plan settings enabled, SQL Server executes the query normally and returns the dataset.

2

Viewing the Estimated Execution Plan

To inspect how SQL Server intends to execute the query, enable SHOWPLAN_ALL.

SET SHOWPLAN_ALL ON;
GO

SELECT
    order_id,
    order_date,
    customer,
    amount,
    SUM(amount) OVER
    (
        ORDER BY order_date, order_id
    ) AS running_total
FROM orders
ORDER BY customer, order_date, order_id;
GO

Instead of returning rows from the orders table, SQL Server returns an estimated execution plan describing the physical operations that would be performed.

3

Although the exact operators depend on the optimizer and available indexes, the execution plan typically resembles the following sequence:

  1. Read the data from the orders table.

  2. Perform any required sorting for the window function.

  3. Compute the running total using the Window Aggregate operator.

  4. Apply the final ORDER BY.

  5. Return the results.

This visibility into the optimizer's decision-making process is invaluable when diagnosing performance issues.

A Common Pitfall

One of the most common mistakes developers make is assuming that SHOWPLAN_ALL only affects the next query.

It doesn't.

SHOWPLAN_ALL is a session-level setting.

Once enabled, every subsequent query in the same session returns an execution plan instead of executing.

For example, after running:

SET SHOWPLAN_ALL ON;
GO

Even a simple query such as:

SELECT *
FROM orders;

returns the execution plan rather than the table data.

4

If you're unaware that SHOWPLAN_ALL is still enabled, it can be quite confusing because every query appears to "stop working."

The Solution

The fix is straightforward.

Disable the session setting.

SET SHOWPLAN_ALL OFF;
GO

After turning it off, SQL Server immediately resumes normal execution.

5

Running the same query again returns the expected dataset.

Why This Happens

Many SQL Server settings persist for the duration of the current session.

SHOWPLAN_ALL is one of them.

Other commonly used session-level settings include:

  • SHOWPLAN_XML

  • STATISTICS IO

  • STATISTICS TIME

  • NOCOUNT

Understanding session scope is important when troubleshooting unexpected SQL Server behavior, particularly during performance tuning.

Why Every Data Engineer Should Understand Execution Plans

As data volumes continue to grow, query performance becomes increasingly important.

Execution plans provide insights that cannot be obtained simply by reading the SQL statement.

They help answer questions such as:

  • Is SQL Server performing a Table Scan or an Index Seek?

  • Is an unnecessary Sort operation occurring?

  • Which operator consumes the highest estimated cost?

  • Is the optimizer using a Window Aggregate efficiently?

  • Can the query be rewritten to reduce resource consumption?

These are exactly the questions that distinguish writing SQL from engineering performant SQL solutions.

Key Takeaways

If you regularly work with SQL Server or Microsoft Fabric SQL Database, keep the following in mind:

  • SHOWPLAN_ALL returns the estimated execution plan without executing the query.

  • It is a session-level setting, not a one-time command.

  • Every query continues returning execution plans until the setting is explicitly disabled.

  • Use SET SHOWPLAN_ALL OFF to restore normal query execution.

  • Learning to interpret execution plans is an essential performance tuning skill for data engineers and database professionals.

Final Thoughts

Window functions, Common Table Expressions (CTEs), and complex analytical queries are becoming increasingly common in modern data platforms. While writing these queries correctly is important, understanding how the SQL Server Query Optimizer executes them is what enables us to build scalable and efficient data solutions.

SHOWPLAN_ALL offers a simple yet powerful way to inspect the optimizer's strategy before a query is executed. Combined with graphical execution plans and tools such as STATISTICS IO and STATISTICS TIME, it forms an essential part of every data engineer's SQL performance tuning toolkit.

The next time you're optimizing a query, don't just verify that it returns the correct result—take a few minutes to examine how SQL Server plans to execute it. The insights you gain can often reveal opportunities for significant performance improvements.