Skip to content

fix(datagrid): show typed EXPLAIN results in the plan viewer (#1480)#1488

Merged
datlechin merged 3 commits into
mainfrom
fix/explain-typed-routing
May 29, 2026
Merged

fix(datagrid): show typed EXPLAIN results in the plan viewer (#1480)#1488
datlechin merged 3 commits into
mainfrom
fix/explain-typed-routing

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #1480

Problem

Running EXPLAIN ANALYZE (or EXPLAIN FORMAT=JSON/FORMAT=TREE) by typing it in the editor put the plan into the data grid, where it collapsed to one truncated line (-> Limit: 5 row(s) (cost=… (actual…) and was unreadable.

TablePro already has a plan viewer (ExplainResultView with Raw/Tree/Diagram). The toolbar "Explain" button routes into it, but a hand-typed explain statement went through the normal query path into the grid, where sanitizedForCellDisplay replaces every newline with a space and truncates at 300 chars. The two paths were split; the typed one never reached the viewer.

Fix

Route typed explain results to the existing viewer, reusing all the current explain infrastructure.

  • QueryClassifier.isExplainStatement(_:) detects a leading EXPLAIN with a word boundary (covers EXPLAIN, EXPLAIN ANALYZE, EXPLAIN (…), EXPLAIN FORMAT=JSON, EXPLAIN QUERY PLAN; excludes DESCRIBE, DESC, EXPLAINING).
  • applyPhase1Result routes to a new applyExplainResult when the statement is an explain and the result has exactly one column. The single-column condition is the safe trigger: it captures the unreadable tree/JSON/text plans while leaving multi-column tabular plans (MySQL's plain EXPLAIN, SQLite's EXPLAIN QUERY PLAN) in the grid, where a table is the right presentation. This one site covers both the normal and parameterized typed paths.
  • resolveTableEditability returns non-editable for explain statements, so an EXPLAIN … FROM orders no longer triggers a needless schema/count fetch.

Untouched on purpose: sanitizedForCellDisplay (correct for the grid) and the working toolbar variant path.

Behavior

  • EXPLAIN ANALYZE SELECT … (MySQL) → plan viewer, Raw mode: full multi-line tree, monospaced, scrollable, with Copy.
  • EXPLAIN FORMAT=JSON SELECT … → plan viewer with Diagram/Tree/Raw (JSON parsed into the tree).
  • EXPLAIN SELECT … (MySQL traditional, multi-column) → stays in the grid as a table. No regression.
  • PostgreSQL typed EXPLAIN … (single QUERY PLAN column) → plan viewer.

Tests

QueryClassifierExplainTests covers the detection (the check that would have caught this class of bug). The behavioral routing needs the coordinator stack, so it is verified manually.

How to verify

  1. MySQL/MariaDB connection, query tab.
  2. Run EXPLAIN ANALYZE SELECT * FROM your_table LIMIT 5;.
  3. Before: one truncated grid cell. After: the readable plan viewer.

Follow-up (not in this PR)

MySQL's EXPLAIN ANALYZE tree text only gets Raw mode; the parser is JSON-only. A tree-text parser would unlock Tree/Diagram for it.

@datlechin datlechin merged commit 596f8a1 into main May 29, 2026
3 checks passed
@datlechin datlechin deleted the fix/explain-typed-routing branch May 29, 2026 20:42
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.

feat: Enhance show result from "EXPLAIN ANALYZE..." command

1 participant