explain_query
Plan a SELECT query to estimate its cost before execution, useful for large tables, missing WHERE clauses, or multiple joins. Avoids running the query, showing only the plan.
Instructions
Plan a SELECT without executing it.
Use this before run_query when the query touches a large table, has no WHERE clause, or joins several tables, so you can see the cost before committing to it. The query is planned only; no rows are read and nothing is executed. EXPLAIN ANALYZE is deliberately not offered, because it would run the statement.
Read total_cost as a relative number, useful for comparing two phrasings of the same query rather than as a time.
On failure:
"Blocked: ..." means the same read-only policy as run_query rejected it. Rewrite as a plain SELECT.
A "column does not exist" error means the schema assumption was wrong. Call describe_table and fix the column names.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | ||
| note | No | ||
| plan | Yes | EXPLAIN output, one line per plan node. | |
| plan_rows | No | Planner's estimated output row count. | |
| total_cost | No | Planner's estimated total cost of the top node. |