Skip to content

[EPIC] Complete SQL EXPLAIN Tree Rendering #14914

Closed
@irenjj

Description

@irenjj

Is your feature request related to a problem or challenge?

#14677 introduces basic tree rendering for SQL EXPLAIN output but requires follow-up work to improve completeness, test coverage, and code quality. Below are the key tasks and enhancements needed:

Here is an example of running the new explains:

set datafusion.explain.format = 'tree';
create table foo(x int, y int) as values (1,2), (3,4);
explain select * from foo where x = 4;

The output looks like

+---------------+------------------------------------+
| plan_type     | plan                               |
+---------------+------------------------------------+
| logical_plan  | Filter: foo.x = Int32(4)           |
|               |   TableScan: foo projection=[x, y] |
| physical_plan | ┌───────────────────────────┐      |
|               | │    CoalesceBatchesExec    │      |
|               | └─────────────┬─────────────┘      |
|               | ┌─────────────┴─────────────┐      |
|               | │         FilterExec        │      |
|               | └─────────────┬─────────────┘      |
|               | ┌─────────────┴─────────────┐      |
|               | │       DataSourceExec      │      |
|               | │    --------------------   │      |
|               | │    partition_sizes: [1]   │      |
|               | │       partitions: 1       │      |
|               | └───────────────────────────┘      |
|               |                                    |
+---------------+------------------------------------+

Items to complete

Information Completion for all ExecutionPlans

The current implementation lacks detailed information for many physical plans.

Add rendering logic for missing operators (In every physical plan's fmt_as function).

New Features:

Process / Documentation

  • Document the tree explain in the user documentation
  • Add upgrade guide in 47 for TreeRender in DisplayFormatType`
  • Use tree explain by default

Test Coverage Expansion

  • Add tests for plans with long metrics (e.g., partition_sizes: [20, 20, 20, 30, ...]) to validate line-wrapping and truncation logic.
  • Tests for TPCH queries (e.g., Q5, Q9) to test rendering of deeply nested plans.
  • Validate alignment and indentation for multi-level operators.

Code Cleanup & Improvements

TODOs

Make variables (e.g., indentation size, truncation thresholds) configurable:

// TODO: Make these variables configurable.  
Dead Code Removal

Remove or utilize the unused Coordinate struct:

#[allow(dead_code)]  
pub struct Coordinate { ... }  
// TODO: It's never used.  

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions