Query Store history of one query
get_query_store_historyRetrieve a query's Query Store history: text, compile SET options, plans, and per-interval runtime stats and waits to diagnose performance changes.
Instructions
Returns the Query Store history of one query: its text (the first 4000 characters); the SET options it compiled with, such as ARITHABORT, which explain a query fast in SSMS and slow in the application; its plans (the 20 that ran most in the window, when it has more) with when each was first and last compiled and whether it is forced; and, per plan and per day, hour or Query Store interval, the executions (aborted and failed ones included, and also counted apart), average and maximum duration, average CPU, logical and physical reads, average and maximum DOP, and average rows, memory and tempdb, plus each plan's waits by category over the whole window. Use it with a query_id from list_query_store_regressions or find_query_store_queries; to see what a plan does use get_query_plan_summary with its plan_id. The Query Store keeps each plan's first and last compile time, not every recompilation.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"database": "<database>",
"query_id": "<query_id>"
},
"name": "get_query_store_history"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No | Days back to cover (default 7). | |
| database | Yes | Name of the database as registered in the configuration. | |
| query_id | Yes | Query Store query id, from list_query_store_regressions or find_query_store_queries. | |
| granularity | No | One row per plan and per 'day' (default), 'hour' or 'interval', the Query Store's own interval. Rows are capped at 400, the newest kept. | day |