Skip to content

feat(explain): ask for the plan in JSON or as an iterator tree - #657

Merged
EVWorth merged 2 commits into
mainfrom
feat/explain-formats
Sep 12, 2026
Merged

EVWorth merged 2 commits into
mainfrom
feat/explain-formats

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Closes #424.

EXPLAIN only ever asked for the tabular plan, which rounds off the numbers worth having. EXPLAIN FORMAT=JSON carries query_cost, read_cost, rows_examined_per_scan and filtered; FORMAT=TREE is the iterator tree, which is the shape EXPLAIN ANALYZE reports in and therefore the one to compare a timed run against.

What it looks like

A Format picker on the plan panel re-plans the last statement in the chosen shape — a select rather than three buttons, because the panel already has a Table/Tree toggle for how to draw the tabular plan and a second "Tree" beside it would be two different things wearing the same word.

JSON renders as a collapsible tree with the cost and row keys picked out. Pretty-printed text would bury them: in a plan for a real query, query_cost is four levels down.

The combinations the servers do not have

Resolved in Rust rather than left to fail, because an error where a plan should be is a worse answer than the plan you can have:

MariaDB, FORMAT=TREE error 1791 — the tabular plan is produced, and the panel says why
MySQL before 8.3, ANALYZE + JSON error 1235 — the plan comes back in JSON without the timings, and the panel says so
MariaDB, ANALYZE + JSON ANALYZE FORMAT=JSON, which does carry r_total_time_ms

Every row of that table was run against MySQL 8.0.46 and MariaDB 11.8 before it was written down. There is also a test that sweeps all twelve combinations of format × analyze × server and asserts none of them builds a statement neither server would run.

The ANALYZE safety check (#412) is untouched and applies to every format — a test plans a DELETE in each of the three and confirms it is refused in all of them.

Tests

+8 Rust unit tests on the statement builder, +5 live-server tests (passing on both servers), +8 frontend tests. 2723 unit, 344 browser.

One thing found while doing this

Running the EXPLAIN integration suite against MariaDB turned up a real bug that is not about EXPLAIN: after a query timeout, the timed-out connection is never returned to the pool, so pool_max timeouts exhaust the pool and disconnect hangs. On MySQL the same code recovers immediately. Filed and fixed separately — this PR leaves a note at the port override pointing at it.

EXPLAIN only ever asked for the tabular plan. That form rounds off the
numbers worth having: `query_cost`, `read_cost`, `rows_examined_per_scan`
and `filtered` all live in `EXPLAIN FORMAT=JSON`, and the iterator tree
is the shape `EXPLAIN ANALYZE` reports in, so it is the one to compare a
timed run against.

A Format picker on the plan panel re-plans the last statement in the
chosen shape. JSON renders as a collapsible tree with the cost and row
keys picked out — pretty-printed text would bury them four levels down.

The combinations the servers do not have are resolved in Rust rather
than left to fail:

- MariaDB has no FORMAT=TREE (error 1791), so it gets the tabular plan
  and the panel says why.
- MySQL before 8.3 cannot combine ANALYZE with JSON (error 1235), so the
  plan comes back in JSON without the timings, and the panel says so.
- MariaDB spells the timed JSON form `ANALYZE FORMAT=JSON`, which does
  carry the timings.

Every one of those was checked against MySQL 8.0.46 and MariaDB 11.8
before it was written down, and there is a test asserting no combination
of format, analyze and server produces a statement neither will run.

The ANALYZE safety check is unchanged and applies to every format —
there is a test that plans a DELETE in each of the three and confirms it
is refused.

+8 Rust unit tests, +5 live-server tests (passing on both servers), +8
frontend tests.
@EVWorth
EVWorth merged commit 88c62af into main Sep 12, 2026
12 checks passed
@EVWorth
EVWorth deleted the feat/explain-formats branch September 12, 2026 05:07
@EVWorth EVWorth mentioned this pull request Sep 12, 2026
9 of 16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1][bug] EXPLAIN doesn't support EXPLAIN FORMAT=JSON or EXPLAIN FORMAT=TREE — only classic tabular format

1 participant