
Enable Query Store to Track Query Performance Changes
If you’re troubleshooting slow queries by relying only on execution plans or SQL Profiler, you’re missing one of SQL Server’s most powerful built-in performance tuning features: Query Store.
Query Store automatically captures:
- Query execution history
- Execution plans
- Runtime statistics
- Performance regressions
- Plan changes over time
This makes it much easier to identify when a query suddenly becomes slow after a deployment, statistics update, or parameter sniffing issue.
Why use Query Store
Many performance problems aren’t caused by bad SQL code. They’re caused by SQL Server choosing a different execution plan.
Without historical data, it’s difficult to determine:
- When the slowdown started
- Which execution plan changed
- Whether performance regressed after an update
Query Store keeps this history, allowing DBAs to compare previous and current execution plans and restore a better-performing plan if necessary.
Example
Enable Query Store
ALTER DATABASE YourDatabase
SET QUERY_STORE = ON;
View Top Resource-Consuming Queries
SELECT TOP (10)
q.query_id,
qt.query_sql_text,
rs.avg_duration,
rs.avg_cpu_time,
rs.count_executions
FROM sys.query_store_query_text qt
JOIN sys.query_store_query q
ON qt.query_text_id = q.query_text_id
JOIN sys.query_store_plan p
ON q.query_id = p.query_id
JOIN sys.query_store_runtime_stats rs
ON p.plan_id = rs.plan_id
ORDER BY rs.avg_duration DESC;
Impact of Query Store
Without Query Store:
- You only see the current execution plan.
- You lose visibility into historical performance.
- Troubleshooting becomes reactive and time-consuming.
With Query Store:
- Detect performance regressions quickly.
- Compare execution plans side by side.
- Force a previously efficient plan when appropriate.
- Reduce downtime caused by unexpected plan changes.
Pro Tip
After major deployments, index maintenance, or statistics updates, review Query Store for plan regressions. If a new plan performs poorly, use Plan Forcing as a temporary mitigation while investigating the root cause.
Key Takeaway
Query Store transforms performance tuning from guesswork into evidence-based troubleshooting. If you’re not using it in production, you’re missing one of SQL Server’s most valuable diagnostic tools.
Discover more from Technology with Vivek Johari
Subscribe to get the latest posts sent to your email.



