Detect SQL Server Plan Regression

Compare queries that slowed after a plan change using Query Store data. Use moon to track regression signals across production periods.

2026-09-25 · 2 min read

Why this problem matters

A statistics, schema, or data-distribution change can cause a more expensive plan to be selected for the same query. Users may observe a sudden duration or CPU increase even without a deployment.

How to diagnose it

Compare Query Store runtime intervals by plan identifier and determine when the change occurred. Verify that higher duration is not instead explained by execution count, parameters, waits, or concurrency changes.

The query lists plan and runtime intervals in the current database for comparison. A short or partially populated current interval should not be compared directly with completed intervals.

SELECT TOP (50)
       q.query_id,
       p.plan_id,
       rsi.start_time,
       rsi.end_time,
       rs.count_executions,
       rs.avg_duration,
       rs.avg_cpu_time,
       rs.avg_logical_io_reads
FROM sys.query_store_query AS q
JOIN sys.query_store_plan AS p ON p.query_id = q.query_id
JOIN sys.query_store_runtime_stats AS rs ON rs.plan_id = p.plan_id
JOIN sys.query_store_runtime_stats_interval AS rsi
  ON rsi.runtime_stats_interval_id = rs.runtime_stats_interval_id
ORDER BY q.query_id, rsi.start_time DESC;

A safe solution approach

The root correction may involve indexes, statistics, or query design, while plan forcing can be considered as a controlled temporary measure. Revalidate the applicability and performance of forced plans after later schema changes.

Why continuous monitoring matters

Regressions may appear only during certain workload periods and be hidden in a single average. moon can track duration and resource trends and route relevant deviations to Slack, PagerDuty, or webhooks.

Frequently asked questions

Does a higher average duration always mean plan regression? Should a previously good plan be forced permanently?

No, workload volume and parameter mix can also alter the average. Plan forcing should be monitored and periodically reassessed for failures and changing data conditions.

How does moon help with this problem?

moon continuously observes SQL Server, PostgreSQL, and MongoDB signals, helping teams evaluate the problem as a trend instead of relying on a one-time check.