# Analyze queries

> How to analyze queries to identify performance problems. A step-by-step method.
>
> Source : https://www.pachadata.com/en/docs/howtos/troubleshooting/analyze-queries/
> Author : Rudi Bruchez · updated 2026-10-14
> Markdown version of the page, for tools and LLMs. The HTML page is the reference.


Here is a condensed checklist of the method for analyzing the performance of a query, or of a SQL Server database.

## 1. Look at the I/O — `SET STATISTICS IO ON`

- If there is a lot of I/O on a table, is there an index on it? ([video, in French](https://youtu.be/BqmaDUumoxk))

## 2. Look at the time — `SET STATISTICS TIME ON`

- `SET STATISTICS IO, TIME ON` ([video, in French](https://youtu.be/wThNVZciebQ))
- Mind the difference between CPU time and total elapsed time.
- CPU < elapsed ⇒ waits. Not the query's fault: lock blocking, disk reads, or the behavior of the client's data reader ([video, in French](https://youtu.be/AbmUxVNF-Pc)).
- CPU > elapsed ⇒ parallelism ([video, in French](https://youtu.be/pqaZPhpXt1w)). Not a problem in itself.

## 3. Look at the actual execution plan

- Is there a discrepancy in the cardinality estimate? Under-estimation is the dangerous direction.
- Prefer [Plan Explorer](https://www.solarwinds.com/free-tools/plan-explorer) for reading plans.
- If there is a discrepancy, update the statistics ([video](https://youtu.be/a-0JJNXdVsw), and [this one](https://youtu.be/FEZSpL36O_w) for updating them from the maintenance plan — both in French).
- It could be a table variable: if so, use `OPTION (RECOMPILE)`, or SQL Server 2017 and later.
- It could be the Cardinality Estimator itself.
  - On a cardinality estimation error in a complex query, experiment with the CE version.
  - `OPTION (USE HINT('FORCE_LEGACY_CARDINALITY_ESTIMATION'))`
  - `OPTION (USE HINT('ASSUME_JOIN_PREDICATE_DEPENDS_ON_FILTERS'))`
  - `OPTION (USE HINT('FORCE_DEFAULT_CARDINALITY_ESTIMATION'))`
  - `ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = ON;`

## 4. Analyze performance across the whole workload

- Use Extended Events, filtering on duration.
- Use Extended Events with no filter for a short while, to see whether there are repetitive or duplicated queries.
- Look at the query statistics: [`dm_exec_query_stats`](https://github.com/rudi-bruchez/tsql-scripts/blob/main/diagnostics/execution-stats/dm_exec_query_stats.sql).

### Use the Query Store (SQL Server 2016 and later)

- [DataFrogs session — Nicolas Souquet, Tout savoir sur le Query Store](https://youtu.be/Adwtl1QtYvI) (in French)
- [DataFrogs session — Query Store, bientôt incontournable](https://youtu.be/EVchvLCk-IQ) (in French)


---

## About the author

Rudi Bruchez, independent SQL Server consultant since 2006: performance audits, tuning, migrations, high availability and training. For an audit or hands-on help on your server: https://www.pachadata.com/en/contact/ (remote audit: https://www.pachadata.com/en/services/remote-sql-server-audit/).
