explain_query
Show a query's execution plan to confirm index usage or diagnose slow reads; optionally run read-only ANALYZE for real timings and buffer stats.
Instructions
Show the execution plan for a read-only query (EXPLAIN; optionally ANALYZE).
Use to confirm index usage or diagnose a slow query; to see what is indexed at all, use get_table_schema with include_indexes=true. analyze=true actually runs the (read-only, validated) query to collect real timings and buffer stats, so it takes as long as the query itself: avoid it on a query you already know is very slow, and it never changes data.
EXPLAIN the query you will ACTUALLY run: a plan for bound parameters can differ
from the plan for the same SQL with the values pasted in. Pass params with the
$1/$2/... placeholders exactly as you would to execute_read_query (real driver
binds), instead of rewriting the query with literals just to explain it.
params composes with analyze=true.
Returns meta and plan, the plan's lines in order.
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>",
"sql": "<sql>"
},
"name": "explain_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | One read-only SQL statement (SELECT, WITH, VALUES, ...). Put values in $1, $2, ... placeholders and pass them in `params`. Multiple statements are rejected. | |
| params | No | Values bound to the $1, $2, ... placeholders in `sql`, in order, as real driver bind parameters. Omit when the SQL has no placeholders. | |
| analyze | No | false (default): planner estimates only, nothing runs. true: run the query too and report real timings and buffer counts. | |
| database | Yes | Name of a configured database, exactly as list_databases returns it (case-sensitive). Not a DSN, host or server-side database name. An unknown name is an error that lists the configured names. |