Estimated plan of a procedure or a query
get_estimated_planCompiles a stored procedure or SELECT with supplied parameter values under SHOWPLAN_XML and summarizes the estimated plan SQL Server would use, including costs, warnings and missing indexes.
Instructions
Compiles a stored procedure for the parameter values given, or one SELECT, under SET SHOWPLAN_XML ON, and summarizes the plan SQL Server would use now, as get_query_plan_summary does for a Query Store plan: per statement the estimated rows, cost and share of the whole, parallelism, the compiled parameter values, the statistics used, warnings, missing indexes and the costliest operators. Nothing runs (but for a deterministic CLR function with constant arguments, which SQL Server evaluates while compiling), and the plan is neither cached nor recorded by the Query Store; but compiling creates missing statistics and updates stale ones, as running would (with AUTO_UPDATE_STATISTICS_ASYNC the update is queued), and the answer names any it changed. When the procedure already has a plan in the plan cache, SQL Server returns that plan, compiled for the values of the run that cached it, and the answer says so (plan_from_cache). Use it to see the plan a procedure gets for given values, or how a rewrite or a hint changes a statement; for the plans that actually ran use get_query_store_history and get_query_plan_summary. A procedure that fills a temporary table with SELECT ... INTO and then reads it cannot be compiled without running: pass its statements in 'query' instead. Statements reading a temporary table or table variable are estimated as if it were empty, dynamic SQL is not compiled, and a CLR procedure has no plan to compile. Needs SHOWPLAN on the database, plus EXECUTE on the procedure or SELECT on what the query reads.
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": "get_estimated_plan"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | One SELECT to compile instead of a procedure, with literal values where a procedure would have parameters (a variable has no value here). CTEs, UNION, subqueries and query hints (OPTION) are accepted, and so are global temporary tables (##name); INTO, any other statement, local temporary tables (#name), linked servers and system functions that open files are refused. At most 32768 characters. Example: "SELECT SecurityId, SUM(Price) FROM dbo.Quote WHERE ReferenceDate = '2026-11-27' GROUP BY SecurityId" | |
| schema | No | Schema of 'procedure'. Empty searches every schema, and fails naming them when the name exists in more than one. Example: 'AutoRegister' | |
| database | Yes | Name of the database as registered in the configuration. | |
| procedure | No | Stored procedure to compile, bare, with no schema prefix: every statement of it is compiled for the values in 'parameters'. Leave empty to compile 'query' instead. Example: 'AutoRegisterEquity' | |
| statement | No | Number of one statement to return alone, its statement_number. 0 (default) returns every statement, or the 20 costliest, with statement_index listing them all, when there are more. | |
| parameters | No | The procedure's values as they follow its name in an EXEC, by name or in order: "@referenceDate = '2026-11-27', @registerType = 'e'". Literals only (text and dates in quotes, numbers, 0x binary, NULL, DEFAULT; a text parameter takes only a value in quotes, since EXEC would pass 007 as '7'); each is converted to its parameter's declared type and sent as a typed parameter, never as SQL, and a value the conversion would change is refused. A parameter left out takes its default (one without a default is an error), an OUTPUT one left out goes as NULL where its type can carry NULL, and a table-valued one cannot be given and compiles empty. | |
| max_operators | No | How many of the costliest operators to keep per statement (default 40, at most 200). Every operator above them comes too, so that the tree reads from the root, and operators_shown can exceed this. |