Find queries in the Query Store
find_query_store_queriesFind Query Store queries by text fragment or procedure, function, or trigger; with no filter, return queries ranked by total duration in a time window, with IDs, plans, and execution metrics.
Instructions
Finds Query Store queries by part of their text or by the procedure, function or trigger that runs them; with neither, the ones that took the most time in the window. Returns each one's query_id, the first 300 characters of its text, its number of plans, its executions in the window with their total and average duration, CPU and logical reads, maximum duration and failed executions, and its last execution. The variants of a parameter-sensitive query (SQL Server 2022+) count under it. Use it to get the query_id that get_query_store_history takes; to find what got slower use list_query_store_regressions. Needs VIEW DATABASE STATE (2022+: VIEW DATABASE PERFORMANCE STATE), which VIEW SERVER STATE implies.
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>"
},
"name": "find_query_store_queries"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| top | No | Most queries to return (default 20, at most 100). | |
| days | No | Days back to add up executions and time over (default 7). | |
| schema | No | Schema of object_name, which it needs. Empty searches every schema. Example: 'Feeder' | |
| database | Yes | Name of the database as registered in the configuration. | |
| object_name | No | Procedure, function or trigger whose statements to list, bare, with no schema prefix. Empty means any query, inside a module or not. Example: 'LoadPrices' | |
| text_pattern | No | Part of the query text, matched anywhere in it as written: brackets, % and _ are plain characters, so a fragment copied from a query_text finds it. At most 1000 characters. Empty means any text. Example: '[dbo].[GenericSecurity]' |