-
Notifications
You must be signed in to change notification settings - Fork 8
feat(explain): redesign EXPLAIN plan visualization with syntax highlighting #745
Copy link
Copy link
Closed
Description
Problem
EXPLAIN output in rpg is currently rendered as plain text — same as psql. For a DBA tool, this is a missed opportunity. The plan is hard to scan at a glance.
Goal
Make EXPLAIN output readable at terminal speed. Inspired by the PostgreSQL EXPLAIN dialect in Pygments (https://pygments.org/docs/lexers/#pygments.lexers.sql.PostgresExplainLexer) — borrow the token grammar and apply terminal colors.
Proposed visualization
Color-code the key elements:
- Node type (Seq Scan, Index Scan, Hash Join, etc.) — bold/cyan
- Cost () — dim, not important unless high
- Actual time () — color-coded: green <10ms, yellow <100ms, red >100ms
- Rows — highlight when estimate vs actual diverge significantly (>10x)
- Filter / Index Cond — highlight in yellow (potential optimization target)
- Buffers — highlight high shared_hit_blocks in a different shade
- Nested loop with high loops — flag visually
The raw text structure (indentation, arrows) must be preserved — we only add color, never reformat.
Reference
- Pygments PostgreSQL EXPLAIN lexer: https://github.com/pygments/pygments/blob/master/pygments/lexers/sql.py (search for PostgresExplainLexer)
- Study the token patterns — port them to Rust regex in
src/explain/(no Python dependency)
Implementation hints
- New module or extend
src/explain/ - Apply coloring only when stdout is a TTY (same guard as other highlighting)
- Respect
--no-highlight/no_highlightsetting - Works for both inline
EXPLAINqueries and the/explainAI command output
Acceptance criteria
- Node types, costs, actual times, and filters are visually distinct
- High row-estimate divergence (>10x) is highlighted
- Coloring disabled correctly when
--no-highlightis set or stdout is not a TTY - Tests for the highlighter (unit tests with sample EXPLAIN output strings)
- Screenshot/recording in PR showing before/after
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels