Skip to content

fix(explain): read the plan the server actually returns - #513

Closed
EVWorth wants to merge 4 commits into
fix/explain-analyze-safety-and-timeoutfrom
fix/explain-plan-rendering
Closed

EVWorth wants to merge 4 commits into
fix/explain-analyze-safety-and-timeoutfrom
fix/explain-plan-rendering

Conversation

@EVWorth

@EVWorth EVWorth commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Closes #422, closes #423, closes #426.

Second of three PRs for area/explain. Stacked on #512 — review that first; this targets its branch and will retarget to main once it lands.

Rendering fixes

#423 — the tree view. It grouped rows by id and made every later group a child of the first group's last node, so a UNION rendered as unrelated flat nodes.

Worth flagging: the issue's premise is wrong. It states a UNION's inner SELECTs "both have id=1". They don't — MySQL gives them ids 1 and 2 plus a third UNION RESULT row whose table reads <union1,2>, naming its members explicitly. <derivedN> and <subqueryN> work the same way. I built the tree off those explicit edges rather than off the issue's description; same-id rows stay siblings because they're one SELECT's join order, and nesting under the nearest lower id is only the fallback. A UNION RESULT with no id of its own (MySQL 5.7 leaves it NULL) sorts just past its members. The stated acceptance criterion still holds.

Test cases are transcribed from real EXPLAIN output rather than invented.

#422 — MariaDB ANALYZE. Two layers, and the second only became visible once the first was fixed:

  • MariaDB answers ANALYZE with the same columns as EXPLAIN, not MySQL's single column of TREE text. The text view joined those with newlines — a wall of one word per line. Now routed on the shape the backend reports.
  • Underneath that, the executor decides "does this return rows?" by prefix match, and the list held only SELECT/SHOW/DESCRIBE/EXPLAIN. ANALYZE wasn't in it, so on MariaDB the feature returned nothing at all. WITH ... SELECT lost its rows the same way, as would TABLE and VALUES. Replaced with a whole-word check over a fuller list.
  • With the rows arriving, MariaDB's ANALYZE turns out to carry r_rows/r_filtered — the measured values that are the whole reason to run ANALYZE. The table renders them when present, so ANALYZE no longer looks identical to EXPLAIN.

The row-limit prefix list is deliberately left alone: appending LIMIT to an ANALYZE or EXPLAIN would rewrite the statement being measured.

#426 — access types. TYPE_COLORS knew eight, so index_merge, fulltext, spatial and ref_or_null rendered as an unexplained grey badge and never reached the legend. The rank map, colour map and legend were three places that had to agree; now one ordered list, which also retires the unused NULL rank (F15 in #411).

Test infrastructure

make db-up could not seed on a Fedora-style host: bind-mounted seed files carry a user_home_t SELinux label, so the container is denied even as root. MariaDB refused to start; MySQL came up silently empty. :ro,z relabels them — the documented fix, a no-op without SELinux.

The readiness check was wrong too, which only surfaced once seeding actually ran. MySQL serves init scripts from a temporary server started with --skip-networking, so a socket mysqladmin ping answers "healthy" while port 3306 is still closed — connect on that and you get an EOF. Healthchecks now ping over TCP, which the temporary server doesn't listen on.

MariaDB is wired into db-up/db-down/db-seed alongside MySQL 8, so dialect differences are testable.

Verification

explain_integration now runs against both MySQL 8 and MariaDB 11.8 — 10 tests, including that MariaDB's ANALYZE comes back tabular with r_rows/r_filtered, and that the DELETE refusal from #512 holds on MariaDB too. 1623 frontend tests pass; clippy/tsc/dprint clean.

🤖 Generated with Claude Code

EVWorth and others added 4 commits August 28, 2026 18:16
Three rendering faults, all from assuming a narrower shape than EXPLAIN
really has.

The tree view grouped rows by id and made every later group a child of the
first group's last node. For a UNION that produced unrelated flat nodes and
dropped the relationship entirely. Real output has more to work with than
the numbering: a UNION RESULT row names its members in the table column as
`<union1,2>`, and `<derivedN>`/`<subqueryN>` name a materialised input the
same way. Treat those as explicit parent-child edges, keep same-id rows as
siblings because they are one SELECT's join order, and fall back to nesting
under the nearest lower id only where MySQL has told us nothing. A UNION
RESULT with no id of its own — MySQL 5.7 leaves it NULL — sorts just past
its members so it still lands in the right place. (#423)

MariaDB answers `ANALYZE` with the same twelve columns as EXPLAIN, not with
MySQL's single column of TREE text, and the text view joined those columns
with newlines: a wall of one word per line. Route on the shape the backend
reports rather than on which button was pressed. (#422)

TYPE_COLORS knew eight access types, so index_merge, fulltext, spatial and
ref_or_null rendered as an unexplained grey badge and never appeared in the
legend. The rank map, the colour map and the legend were three places that
had to agree; they are now one ordered list, which also retires the unused
NULL rank. (#426)

The tree cases are transcribed from real EXPLAIN output on MySQL 8 rather
than invented — the reported UNION shape in #423 was not what the server
actually returns.

Refs #422, #423, #426

Co-Authored-By: Claude Opus 5 <[email protected]>
`make db-up` could not seed on a Fedora-style host. The bind-mounted seed
files carry a user_home_t label, so the container is denied even as root:
MariaDB refused to start at all, and MySQL came up silently empty. Adding
:ro,z relabels them to container_file_t, which is the documented fix and a
no-op on hosts without SELinux.

The readiness check was also wrong in a way that only showed up once the
seeding actually ran. MySQL's entrypoint serves the init scripts from a
temporary server started with --skip-networking, so `mysqladmin ping` over
the socket answers "healthy" while port 3306 is still closed; anything that
connected on the strength of it got an EOF moments later. The healthchecks
now ping over TCP, which the temporary server does not listen on, and
db-up waits on container health rather than running its own ping.

MariaDB is brought up alongside MySQL 8 and torn down with it, because its
dialect differs in ways worth testing against — ANALYZE rather than
EXPLAIN ANALYZE being the immediate one.

Co-Authored-By: Claude Opus 5 <[email protected]>
…LUES

The executor decides whether a statement answers with a result set by
matching a prefix, and the list held only SELECT/SHOW/DESCRIBE/EXPLAIN.
Rows are accumulated either way, so anything outside that list had its rows
thrown away and reported as a bare rows_affected instead.

MariaDB spells EXPLAIN ANALYZE as `ANALYZE <stmt>`, so on MariaDB the whole
feature returned nothing at all — which is what the tabular-output report
in #422 was really sitting on top of. `WITH ... SELECT` lost its rows the
same way, as would TABLE and VALUES.

Replaced with a whole-word check over a fuller list, so DESCRIBE is not
read as DESC and a table named SELECTIONS is not read as SELECT. The
row-limit list is deliberately left alone: appending LIMIT to an ANALYZE or
EXPLAIN would rewrite the statement being measured.

With the rows arriving, MariaDB's ANALYZE turns out to carry r_rows and
r_filtered next to the estimates — the measured values that are the entire
reason to run ANALYZE. The table view renders those two columns when the
server sends them, so ANALYZE no longer looks identical to EXPLAIN.

Verified against MariaDB 11.8 and MySQL 8 in explain_integration.

Refs #422

Co-Authored-By: Claude Opus 5 <[email protected]>
Two more from the review of this stack.

Adding WITH to the row-returning list fixed `WITH ... SELECT` losing its
rows but broke the other half: `WITH doomed AS (...) DELETE FROM t` matched
on the leading WITH, so a delete that had just removed rows was reported as
an empty result set and the UI told the user nothing was affected. The check
now reads the verb the CTE prefixes, via the same helper the ANALYZE safety
decision uses, so both halves are right and cannot drift apart. WITH is no
longer a member of the list at all.

The move to TCP healthchecks was correct for the seeded containers and wrong
for mysql-ssl, which runs --require-secure-transport=ON and therefore
refuses an unencrypted ping: the container never left "starting" with
"Authentication requires secure connection" in its health log. It keeps the
unix socket, which is exempt from that setting, and has no seed script, so
the temporary-server race the TCP checks avoid cannot arise for it.
Confirmed the container now reaches healthy.

Refs #422

Co-Authored-By: Claude Opus 5 <[email protected]>
@EVWorth
EVWorth force-pushed the fix/explain-plan-rendering branch from a27c42f to 320359f Compare August 28, 2026 23:18
@EVWorth
EVWorth deleted the branch fix/explain-analyze-safety-and-timeout August 28, 2026 23:21
@EVWorth EVWorth closed this Aug 28, 2026
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.

1 participant