A SQL query can take several seconds to complete even when its execution plan looks reasonable. Sometimes the query is waiting for another transaction to release a lock. In other cases, SQL Server is waiting for data to be read from storage, memory to become available, or a worker thread to execute the request.
Looking only at execution duration does not tell you which of these situations is responsible. You might spend time rewriting a query or adding indexes when the actual problem is blocking or resource contention elsewhere in the database.
SQL Server Query Store helps investigate these problems by collecting query execution information, execution plans, and wait statistics over time. Instead of relying only on current activity or instance-level wait statistics, developers and database administrators can identify which queries experienced particular waits during a selected period.
This article explains how to enable Query Store wait statistics, identify queries with significant waits, interpret common wait categories, and use the collected information to investigate performance problems.
What Query Store Wait Statistics Tell You
Query Store maintains historical information about queries executed against a database. It stores information in three main areas:
Plan store: Records execution plans associated with queries.
Runtime statistics store: Records execution metrics such as execution count, duration, CPU time, and logical reads.
Wait statistics store: Records the wait categories associated with query plans during execution.
Wait statistics are particularly useful because they help connect a performance problem to a specific query and execution plan.
For example, consider an application that loads an order history page. The page normally loads quickly, but users occasionally experience delays. The query might be waiting for a lock held by another transaction, or it might be spending time reading pages from storage.
Without query-level wait information, you may see a large locking wait or I/O wait at the database level without knowing which application query contributed to it. Query Store provides a historical view that helps narrow down the investigation.
Query Store wait statistics are available starting with SQL Server 2017 and are also supported by Azure SQL Database and Azure SQL Managed Instance. They are not available in SQL Server 2016.
Enabling Wait Statistics Collection
Query Store must be enabled for the database before it can collect query history. Wait statistics collection must also be enabled.
You can configure both settings with the following statement:
ALTER DATABASE [ApplicationDB]
SET QUERY_STORE = ON
(
WAIT_STATS_CAPTURE_MODE = ON
);Replace ApplicationDB with your database name.
If Query Store is already enabled, you can update its wait statistics capture mode separately:
ALTER DATABASE [ApplicationDB]
SET QUERY_STORE
(
WAIT_STATS_CAPTURE_MODE = ON
);After enabling collection, SQL Server starts recording wait information for query executions. The data is aggregated into runtime statistics intervals rather than being stored as a separate record for every individual execution.
This distinction matters when investigating short-lived problems. Query Store is designed for historical performance analysis, not as a real-time event trace. If you need to investigate a query that is currently blocked, you should also examine active requests and blocking sessions.
You can check the current Query Store configuration using:
SELECT
actual_state_desc,
wait_stats_capture_mode_desc,
current_storage_size_mb,
max_storage_size_mb,
readonly_reason
FROM sys.database_query_store_options;Review the output before relying on the collected information. If Query Store is read-only, stopped, or not capturing wait statistics, the historical data might not represent the period you are investigating.
Understanding the Main Wait Categories
SQL Server groups individual wait types into categories in Query Store. This makes historical analysis easier because several related wait types can be investigated using a common troubleshooting approach.
The most useful categories to recognize include the following.
Lock waits
Lock waits occur when a query needs access to a resource that another transaction currently holds with an incompatible lock.
For example, one application request might update an order while another request attempts to read or modify the same record. Depending on the isolation level and locking behavior, the second request may have to wait.
Query Store groups lock-related waits under the Lock category. Individual wait types commonly begin with LCK_M_.
When investigating lock waits, examine:
Transactions that remain open for a long time.
Queries that update or delete large numbers of records.
Missing indexes that cause SQL Server to examine more rows than necessary.
Application code that performs database operations while holding a transaction open.
Blocking chains involving multiple sessions.
Adding an index can sometimes reduce the number of rows or pages a query must access, but it does not automatically resolve every blocking problem. You must identify the transaction holding the conflicting lock.
Buffer I/O waits
Buffer I/O waits occur when SQL Server needs a database page that must be read from storage.
A common wait type in this category is PAGEIOLATCH_SH. It indicates that a task is waiting for a page to be read into the buffer pool.
For example, a reporting query might scan a large table and request many pages that are not already available in memory. If storage access is slow or the query reads more data than necessary, execution duration can increase.
Investigate the following:
Large table scans.
Missing or ineffective indexes.
Excessive logical and physical reads.
Storage latency.
Queries retrieving more columns or rows than the application needs.
Do not assume that every buffer I/O wait means the storage system is slow. A query that reads an unnecessarily large amount of data can also create substantial I/O pressure.
CPU waits
The CPU category includes SOS_SCHEDULER_YIELD waits. These waits can appear when a task voluntarily yields the scheduler after using its allotted execution time.
A high CPU wait contribution can indicate CPU scheduling pressure, but it should not be interpreted as a direct measurement of total CPU consumption.
When investigating CPU-related performance problems, compare Query Store wait information with runtime CPU statistics. Also inspect the execution plan for expensive operators, inefficient joins, repeated calculations, and large scans.
Memory waits
Memory-related waits can indicate that queries are waiting for memory resources.
One example is RESOURCE_SEMAPHORE, which is associated with queries waiting for execution memory grants.
This can happen when several memory-intensive queries run concurrently or when a query requests a large memory grant.
Check whether queries are performing large sorts, hash joins, or other operations that require substantial memory. Also investigate whether the estimated row counts in the execution plan differ significantly from the actual workload.
Increasing available memory is not always the right first step. An inefficient query or inaccurate cardinality estimates can create unnecessary memory requirements.
Network I/O waits
The Network I/O category includes ASYNC_NETWORK_IO.
This wait can occur when SQL Server has produced results but is waiting for the client to consume them.
For example, an application might execute a query that returns hundreds of thousands of rows and then process those rows slowly. SQL Server can spend time waiting for the client to receive the result set.
Investigate the amount of data returned, application-side result processing, network conditions, and whether the application really needs every returned row.
Reducing the result set can be more effective than changing the database server configuration.
Transaction log I/O waits
The Tran Log I/O category includes WRITELOG.
This wait is associated with writing transaction log records to storage. It can become important when an application performs frequent writes or large transactions.
Investigate transaction size, write frequency, transaction log storage latency, and the volume of concurrent write activity.
A query that inserts or updates many records can contribute to log I/O pressure, even when its execution plan is otherwise efficient.
Finding Queries With the Highest Wait Times
The sys.query_store_wait_stats catalog view contains the historical wait information collected by Query Store.
It includes the execution plan identifier, runtime statistics interval, wait category, execution type, and wait duration metrics.
The following query identifies plans with the highest total wait time:
SELECT TOP (20)
q.query_id,
p.plan_id,
qt.query_sql_text,
ws.wait_category_desc,
ws.execution_type_desc,
SUM(ws.total_query_wait_time_ms) AS total_wait_time_ms,
SUM(ws.avg_query_wait_time_ms) AS sum_of_average_wait_ms,
MAX(ws.max_query_wait_time_ms) AS max_wait_time_ms
FROM sys.query_store_wait_stats AS ws
INNER JOIN sys.query_store_plan AS p
ON ws.plan_id = p.plan_id
INNER JOIN sys.query_store_query AS q
ON p.query_id = q.query_id
INNER JOIN sys.query_store_query_text AS qt
ON q.query_text_id = qt.query_text_id
GROUP BY
q.query_id,
p.plan_id,
qt.query_sql_text,
ws.wait_category_desc,
ws.execution_type_desc
ORDER BY
total_wait_time_ms DESC;This query groups wait statistics by query plan and wait category.
The total_wait_time_ms column helps identify plans that accumulated substantial waiting time. The max_wait_time_ms column highlights the largest recorded wait in the grouped data.
The sum_of_average_wait_ms column should be treated carefully. It adds averages from multiple runtime intervals, so it is not a single per-execution average across the entire period. For an overall average, use total wait time divided by the corresponding execution count after aggregating the data over the same intervals.
The results help answer an important question: which query plans have contributed most to waiting?
However, a query with a high cumulative wait time is not automatically the slowest query. A frequently executed query can accumulate substantial wait time even if each execution is relatively quick.
For that reason, you should compare wait statistics with execution count and duration before deciding what to optimize.
Filtering Wait Statistics by Runtime Interval
A database can have different workloads throughout the day. A query that performs well during normal business hours might experience blocking during a reporting job or increased I/O during a scheduled batch process.
Query Store associates wait statistics with runtime statistics intervals. You can use these intervals to investigate a particular period.
The following query displays wait categories for each runtime interval:
SELECT
rsi.start_time,
rsi.end_time,
ws.plan_id,
ws.wait_category_desc,
SUM(ws.total_query_wait_time_ms) AS total_wait_time_ms,
MAX(ws.max_query_wait_time_ms) AS max_wait_time_ms
FROM sys.query_store_wait_stats AS ws
INNER JOIN sys.query_store_runtime_stats_interval AS rsi
ON ws.runtime_stats_interval_id = rsi.runtime_stats_interval_id
GROUP BY
rsi.start_time,
rsi.end_time,
ws.plan_id,
ws.wait_category_desc
ORDER BY
rsi.start_time DESC,
total_wait_time_ms DESC;This query helps identify when a particular plan experienced significant waits.
For example, if lock waits increase during a scheduled data import, you can compare that interval with the application's import schedule. If buffer I/O waits increase during a reporting window, investigate whether reporting queries are scanning large tables or competing for storage resources.
For a more focused investigation, add a filter for the plan_id or a specific date range.
Remember that Query Store aggregates statistics into intervals. The result is useful for identifying patterns, but it does not provide the exact start and end time of every individual wait event.
Comparing Wait Statistics With Runtime Performance
Wait statistics are most useful when analyzed alongside query execution metrics.
A query may accumulate a high wait time because it executes frequently, because individual executions are slow, or because it experiences an unusual performance problem during a particular interval.
The following query combines wait information with runtime execution statistics:
SELECT
q.query_id,
p.plan_id,
qt.query_sql_text,
rsi.start_time,
rsi.end_time,
rs.count_executions,
rs.avg_duration / 1000.0 AS avg_duration_ms,
rs.avg_cpu_time / 1000.0 AS avg_cpu_time_ms,
rs.avg_logical_io_reads,
ws.wait_category_desc,
SUM(ws.total_query_wait_time_ms) AS total_wait_time_ms
FROM sys.query_store_plan AS p
INNER JOIN sys.query_store_query AS q
ON p.query_id = q.query_id
INNER JOIN sys.query_store_query_text AS qt
ON q.query_text_id = qt.query_text_id
INNER JOIN sys.query_store_runtime_stats AS rs
ON p.plan_id = rs.plan_id
INNER JOIN sys.query_store_runtime_stats_interval AS rsi
ON rs.runtime_stats_interval_id = rsi.runtime_stats_interval_id
INNER JOIN sys.query_store_wait_stats AS ws
ON ws.plan_id = rs.plan_id
AND ws.runtime_stats_interval_id = rs.runtime_stats_interval_id
AND ws.execution_type = rs.execution_type
GROUP BY
q.query_id,
p.plan_id,
qt.query_sql_text,
rsi.start_time,
rsi.end_time,
rs.count_executions,
rs.avg_duration,
rs.avg_cpu_time,
rs.avg_logical_io_reads,
ws.wait_category_desc
ORDER BY
total_wait_time_ms DESC;This example correlates runtime and wait information using the plan, runtime interval, and execution type.
The duration and CPU values in Query Store runtime statistics are reported in microseconds, which is why the query divides them by 1,000 to display milliseconds.
One important detail is that Query Store can maintain multiple runtime statistics rows for an interval, including in-memory and persisted data. The query above is intended as an investigative starting point. For detailed reporting, aggregate runtime statistics and wait statistics independently by plan, interval, and execution type before joining them. This avoids multiplying values when multiple rows exist for the same interval.
Use this comparison to identify patterns:
High duration and high CPU time can indicate expensive query processing.
High duration with relatively low CPU time can indicate that the query spends substantial time waiting.
High logical reads can point toward inefficient data access.
High lock waits can indicate blocking or long-running transactions.
High buffer I/O waits can justify examining storage latency and query access patterns.
These metrics narrow down the investigation, but the execution plan and workload context are still necessary to identify the root cause.
Using the Query Wait Statistics Report in SSMS
You do not always need to write SQL queries to investigate Query Store data. SQL Server Management Studio provides a Query Wait Statistics report for databases with the required Query Store information.
To open the report:
Connect to the SQL Server instance using SQL Server Management Studio.
Expand the Databases node.
Expand the database you want to investigate.
Expand Query Store.
Open the Query Wait Statistics report.
The report displays the wait categories that contributed to query execution waits. You can select a category to examine the queries associated with it.
The report also provides aggregation choices such as total, average, minimum, maximum, and standard deviation. These options help you investigate different performance patterns.
For example, total wait time is useful when identifying queries with a large cumulative contribution. Maximum wait time can help locate unusually long waits. Average wait time can help compare typical execution behavior, while standard deviation can reveal inconsistent performance.
This is particularly useful when a query is normally fast but occasionally becomes slow. Instead of looking only at its average duration, you can examine whether its wait behavior varies significantly.
The Query Wait Statistics report is available in SQL Server Management Studio versions that support the feature, starting with SSMS 18.0, when used with SQL Server 2017 or later.
Investigating a High Wait Category
Finding a query with high wait time is only the beginning. The next step is to understand why SQL Server is waiting.
Consider a query that has accumulated a large amount of Lock wait time.
Start by locating its query text and execution plan. Check whether the query updates a large number of records, uses an inefficient access path, or runs inside a transaction that remains open longer than necessary.
Next, identify the sessions involved in blocking. For an active blocking problem, you can use the following query to inspect current requests:
SELECT
session_id,
blocking_session_id,
wait_type,
wait_time,
wait_resource,
status,
command
FROM sys.dm_exec_requests
WHERE blocking_session_id <> 0
ORDER BY wait_time DESC;This query shows requests that are currently blocked by another session. It is a live snapshot, not a historical report. A blocking session might finish before you execute the query, so it should be used alongside Query Store history.
If the wait category is Buffer I/O, examine the execution plan and logical reads. Check whether the query scans a large table when a more selective index could be used. Also compare the workload with storage performance information.
If the category is Memory, inspect memory grant information and the operators that require memory. Large hash joins and sorts can contribute to memory pressure, particularly when several queries execute concurrently.
The important point is to investigate the actual resource behind the wait rather than applying a generic optimization.
Keeping Query Store Useful in Production
Query Store is a database-level performance monitoring feature, so it needs basic operational management.
First, monitor its storage consumption and state. Query Store has a configured storage limit. When that limit is reached, it can switch to read-only mode and stop collecting new data.
You can check its current status with:
SELECT
actual_state_desc,
desired_state_desc,
readonly_reason,
current_storage_size_mb,
max_storage_size_mb,
wait_stats_capture_mode_desc
FROM sys.database_query_store_options;If Query Store becomes read-only, investigate the reason before changing its configuration. You may need to increase its storage limit, adjust cleanup settings, or review the capture policy.
Second, choose a capture policy that matches the workload. Capturing every possible query can increase storage usage, especially in databases with many short-lived or dynamically generated statements. Review Query Store configuration periodically rather than assuming the initial settings will remain appropriate as the application grows.
Third, retain enough history to investigate recurring problems. If a performance issue happens once a week but Query Store retains only a short history, the evidence may disappear before the investigation begins.
Finally, remember that Query Store writes its information asynchronously. There can be a delay before recent execution data becomes visible. Do not treat the absence of a newly executed query in a report as proof that the query did not run.
Conclusion
SQL Server Query Store wait statistics provide a practical way to connect historical query performance problems with the resources that queries were waiting for. They help distinguish locking, I/O, memory, CPU scheduling, transaction log, and network-related waits without relying entirely on instance-level wait statistics.
A useful troubleshooting process starts by identifying queries with high wait contributions, comparing their wait information with execution count and duration, and examining the execution plan. From there, investigate the resource indicated by the wait category and confirm the root cause before changing indexes, transactions, query structure, or server configuration.
For production databases, keep Query Store enabled, monitor its storage and capture state, and retain enough history to compare normal and problematic workloads. This turns Query Store from a feature used only during incidents into a valuable source of historical performance information.


Join the conversation! Your thoughts help the community grow.