Save and compare two plans

Two queries can return the same result through different strategies. Saving each plan as .sqlplan preserves the evidence and lets Compare Showplan align both structures.

Save evidence that can be opened again

A .sqlplan file contains Showplan XML. It can preserve operators, properties, statement text, and runtime counters. Review object names, predicates, literals, and other sensitive data before sharing it.

In SSMS, Save Execution Plan As is available from the plan canvas. Open one file and use Compare Showplan to choose the second. The top and bottom positions identify the files; they do not automatically mean “before” and “after.”

How to produce and open the comparison

  1. Open a query window connected to the database that contains dbo.PedidoLaboratorio.
  2. Enable Include Actual Execution Plan with Ctrl+M.
  3. Run only the first query. Results should contain 136, while Execution plan contains that query’s plan.
  4. Right-click an empty area of the plan, choose Save Execution Plan As, and save the file with a name that identifies the direct predicate.
  5. Run only the second query and save its plan under another name.
  6. Open either .sqlplan through File → Open → File. Right-click its canvas, choose Compare Showplan, and select the other file.

SSMS places one plan above the other. Verify the statement text before deciding which query occupies each position. Selecting equivalent operators exposes their top and bottom properties; press F4 if the Properties panel is not visible.

Two queries with the same result

The first query compares the date directly:

DECLARE @Desde date = '2025-01-01';

SELECT COUNT_BIG(*) AS Pedidos
FROM dbo.PedidoLaboratorio AS p
WHERE p.FechaPedido >= @Desde
OPTION (RECOMPILE);

The second transforms the column before comparing it:

DECLARE @Desde date = '2025-01-01';

SELECT COUNT_BIG(*) AS Pedidos
FROM dbo.PedidoLaboratorio AS p
WHERE DATEDIFF(DAY, @Desde, p.FechaPedido) >= 0
OPTION (RECOMPILE);

Both return 136 orders. Result equivalence is the starting point, not the performance conclusion.

Compare Showplan aligns the strategies

Index Scan and Index Seek aligned in Compare Showplan

  1. 1
    Top plan

    The query that transforms the column uses an Index Scan and reads the index before retaining 136 rows.

  2. 2
    Bottom plan

    The direct predicate permits an Index Seek on the same index and returns the same 136 rows.

The comparison view locates branches and structural differences. It does not establish which alternative used fewer reads, CPU, or elapsed time.

Properties remain side by side

Top and bottom properties in Compare Showplan

  1. 1
    Top estimated cost

    The Index Scan plan shows an estimated subtree cost of 0.486179.

  2. 2
    Bottom estimated cost

    The Index Seek plan shows 0.0035137. These are optimizer units, not milliseconds.

  3. 3
    Plan identity

    Each side has a different QueryPlanHash, so these are not the same saved plan.

Also compare rows read and returned, predicates, warnings, memory, and execution counts. A cost percentage does not replace a baseline.

Comparing does not approve a change

The Scan–Seek difference produces a hypothesis: the direct predicate appears to require less work. Test it again with reads, CPU, and elapsed time, and confirm that the rewritten predicate preserves meaning for all relevant parameters.

What we can conclude

The saved files show two strategies for the same result. Compare Showplan aligns their structures and properties, but the decision still requires observed metrics and documented conditions.

A reasonable next check

The next entry uses Query Store to associate plans with time intervals and runtime statistics rather than relying on two manually selected files.

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