Repository navigation
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
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).
- Implement
treeexplain forFilterExec#15000 - Implement tree explain for
DataSourceExec#15029 - Implement
treeexplain forProjectionExec#15023 - Implement
treeexplain forAggregateExec#15024 - Implement
treeexplain forLocalLimitExec#15025 - Implement
treeexplain forGlobalLimitExec#15026 - Implement tree explain for
PartialSortExec#15064 - Implement
treeexplain forSortExec#15076 - feat: Implement tree explain for
RepartitionExecandWorkTableExec#15097 - Implement
treeexplain forBoundedWindowAggExecandWindowAggExec#15083 - Implement tree explain for
SortPreservingMergeExec#15139 - Implement
treeexplain forHashJoinExec#15078 - Implement
treeexplain forNestedLoopJoinExec,CrossJoinExec,SortMergeJoinExecandSymmetricHashJoinExec#15080 - Implement tree rendering for
StreamingTableExec#15086 - Implement
treeexplain forValuesExec#15093 - Implement tree explain for InterleaveExec #15196
- Implement tree explain for LazyMemoryExec #15171
- Implement
treeexplain forForeignExecutionPlan - Implement
treeexplain forJsonSink#15089 - Implement tree explain for CsvSink #15186
- Implement tree explain for
ArrowFileSink#15112 - Implement tree explain for
PlaceholderRowExec#15138 - Implement tree explain for
CoalesceBatchesExec#15141 - Implement tree explain for
CoalescePartitionsExec#15195 - Implement tree explain for UnionExec #15277
- (TODO file more)
New Features:
- Support different
EXPLAINformats via SQL #15021 - Do not print logical plans in
treeexplain format #15020 - Simpler / easier to see expressions in
treeexplain mode #15107 - Simplify the printing of all plans containing
exprintreemode. #15238 - [tree explain] Simplify display format of
AggregateFunctionExpr#15252
Process / Documentation
- Document the
treeexplain in the user documentation - Add upgrade guide in 47 for
TreeRenderin DisplayFormatType` - Use
treeexplain 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
- Improve
explain treeformatting for longer lines / word wrap #15019 - Improve Parsing for KV Format in
treeexplain. #15098
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. Reacted by Marko Milenković and Adrian Garcia Badaracco
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Activity
[-]Tracking Issue: Enhance SQL EXPLAIN Tree Rendering[/-][+][EPIC] Complete `SQL EXPLAIN` Tree Rendering[/+]alamb commentedon Mar 4, 2025
I made a first PR to show how to add tree explain
treeexplain for FilterExec #15001Once we get that one in I plan to file a bunch of other tickets for the remaining
ExplainPlannodesmilenkovicm commentedon Mar 4, 2025
This looks great! Would it be possible to extend this with svg output? It would be great for ballista ui
alamb commentedon Mar 4, 2025
There is already a graphviz version (that kind of looks crappy).
Since the output is text, perhaps there is some way to render text as a svg 🤔
waynexia commentedon Mar 4, 2025
For the setting side, how about using the existing
EXPLAIN [ANALYZE] FORMAT <format>grammar?sqlparsercan parse and generate aAnalyzeFormat, which the planner can use. But our current implementation just drops this format field:datafusion/datafusion/sql/src/statement.rs
Lines 213 to 222 in ed517ef
We can also try to support GRAPHVIZ format in this way, it should be easier to be rendered to svg.
alamb commentedon Mar 5, 2025
This is a great idea @waynexia
It seems like AnalyzeFormat currently only supports Text, JSON, and GRAPHVIZ 🤔
https://docs.rs/sqlparser/latest/sqlparser/ast/enum.AnalyzeFormat.html
It would be a good way to show graphviz plans
alamb commentedon Mar 5, 2025
I filed the following ticket for this
EXPLAINformats via SQL #15021I also filed a ticket to avoid printing logical plans when in tree mode
treeexplain format #15020alamb commentedon Mar 5, 2025
Here is another PR to improve DataSource:
DataSourceExec#15029milenkovicm commentedon Mar 6, 2025
ballista uses graphviz-rust which generates those sub-optimal images (and needs local graph viz installation). spark uses
a javascript framework which works much better for them. Maybe we should keep
dotrepresentation if we already have italamb commentedon Mar 6, 2025
I think that if we just made it easier to use the existing formats, that would be a big win.
niebayes commentedon Mar 10, 2025
Can make
treea subcommand ofexplain, likeexplain tree <your sql>.irenjj commentedon Mar 10, 2025
It looks like this is something that #15021 is going to handle.👀
alamb commentedon Mar 10, 2025
Yes indeed -- maybe you could ask @waynexia if you could do that PR?
alamb commentedon Mar 10, 2025
I also just made
treemode 🧹 #15132To clean up the display a bit
alamb commentedon Mar 21, 2025
Thank you so much to @irenjj @zebsme @Standing-Man and others I think we are basically done with this epic...
It is even documented!
https://datafusion.apache.org/user-guide/sql/explain.html#tree-format
🎉
I think we should consider using
treemode by default. I have filed a ticket to discuss this:treeexplain by default #15343