Skip to content

[P1][bug] buildTree groups EXPLAIN rows by id and treats all same-id rows as siblings — UNION queries produce wrong nesting #423

Closed

Description

@EVWorth

Context

ExplainPanel's tree-view reconstructs a tree from tabular EXPLAIN rows.

Problem

src/components/explain/ExplainPanel.tsx:282-315 (buildTree) groups rows by id and treats all same-id rows as siblings. MySQL EXPLAIN for a UNION produces rows with same id but in different tree positions. For SELECT 1 UNION SELECT 2 EXPLAIN, both inner SELECTs have id=1; both render as flat top-level nodes (wrong). For a subquery (SELECT * FROM a) sub EXPLAIN, the outer SELECT and inner SELECT have different ids (e.g., 1 and 2), so the inner becomes a child of outer — correct for this case. The UNION case is the broken one. ARCHITECTURE §3.2 doesn't explicitly require correct UNION tree representation, but the tree view is the "visual" feature promised by FR-10.2.2.

Files

  • src/components/explain/ExplainPanel.tsx:282-315 (buildTree)

Repro

  1. EXPLAIN SELECT 1 UNION SELECT 2
  2. Tree view shows 2 flat nodes — they should nest under a UNION parent

Expected

SELECT 1 UNION SELECT 2 renders as a single root node with 2 leaf children. SELECT * FROM (SELECT * FROM a) sub renders as a parent (a) and child (subquery).

Proposed fix

Build a proper parent-child tree from id and the table column: a row's parent is the previous row whose id is strictly less than this row's id (standard MySQL EXPLAIN convention). Or use EXPLAIN FORMAT=TREE (MySQL 8.0.16+) and parse that — it's a proper tree. Scope: M.

Acceptance

SELECT 1 UNION SELECT 2 renders as a single root node with 2 leaf children. SELECT * FROM (SELECT * FROM a) sub renders as a parent (a) and child (subquery). The user can visually trace which table the optimiser touched first.

Needs human verify

yes

Doc drift

no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/explainauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions