Explain a query plan
db_explainReturn a statement's execution plan without running it. Detect full table scans and missing indexes safely before executing your query.
Instructions
Return the execution plan for a statement WITHOUT running it. Read-only by construction: the statement is planned and not executed, so this is the safe way to catch a sequential scan over a large table and the cheapest way to find a missing index. ANALYZE variants are refused here on purpose, because "EXPLAIN ANALYZE" runs the statement it plans. MongoDB: pass "collection" and a find filter as "query"; a pipeline cannot be explained, use db_query action "aggregate" with a small limit. Redis has no plans, so this tool refuses it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uri | No | Connection string, for example postgres://user@host/db, mysql://user@host/db, sqlite:///path/to/app.db, mongodb://host/db or redis://host. Pass "profile" wherever db_list shows one. | |
| query | Yes | The statement to plan, without a leading EXPLAIN: this tool adds the right prefix per dialect. Passing EXPLAIN yourself is refused, and so is EXPLAIN ANALYZE in any spelling. For MongoDB it is the find filter as JSON. | |
| params | No | Values bound to placeholders in "query" instead of pasted into it: ? for MySQL and SQLite, $n for PostgreSQL. Prefer this: a bound value never reaches the statement text, the log, or a plan cache. SQL only. | |
| profile | No | A profile name from db_list. Exactly one of "profile" (a name from db_list) or "uri" (an ad-hoc connection string). Prefer "profile": it keeps the password out of the transcript. | |
| timeout | No | Milliseconds before giving up on the planner (default 30000, between 1 and 86400000). | |
| collection | No | MongoDB only, and required there: a plan is a plan for one collection. Ignored elsewhere, where the statement names its own tables. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | False when the call failed; read "error" then. | |
| hint | No | ||
| rows | Yes | The result. Null if a result limit dropped it. | |
| bytes | Yes | ||
| error | No | Present only when "ok" is false. | |
| driver | No | ||
| format | Yes | Rendering used for the text content block. | |
| profile | No | ||
| rowCount | Yes | ||
| timezone | No | ||
| elapsedMs | Yes | ||
| truncated | Yes | True when a limit removed something: the result is a prefix, not the answer. | |
| nextCursor | No | ||
| limitReason | No | maxRows or maxBytes, when the result was truncated. |