Repository navigation
[EPIC] Complete SQL EXPLAIN Tree Rendering #14914
Description
Activity
- changed the title
[-]Tracking Issue: Enhance SQL EXPLAIN Tree Rendering[/-][+][EPIC] Complete `SQL EXPLAIN` Tree Rendering[/+]on Feb 28, 2025 I made a first PR to show how to add tree explain
Once we get that one in I plan to file a bunch of other tickets for the remaining
ExplainPlannodesReacted by irenjj, Namgung Chan, Sasha Syrotenko and Andy YenThis looks great! Would it be possible to extend this with svg output? It would be great for ballista ui
This looks great! Would it be possible to extend this with svg output? It would be great for ballista ui
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 🤔
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
Statement::Explain { verbose, statement, analyze, format: _, describe_alias: _, .. } => { self.explain_to_plan(verbose, analyze, DFStatement::Statement(statement)) } We can also try to support GRAPHVIZ format in this way, it should be easier to be rendered to svg.
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
Statement::Explain {
verbose,
statement,
analyze,
format: _,
describe_alias: _,
..
} => {
self.explain_to_plan(verbose, analyze, DFStatement::Statement(statement))
}
We can also try to support GRAPHVIZ format in this way, it should be easier to be rendered to svg.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
For the setting side, how about using the existing EXPLAIN [ANALYZE] FORMAT grammar? sqlparser can parse and generate a AnalyzeFormat, which the planner can use. But our current implementation just drops this format field:
I filed the following ticket for this
I also filed a ticket to avoid printing logical plans when in tree mode
Here is another PR to improve DataSource:
This looks great! Would it be possible to extend this with svg output? It would be great for ballista ui
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 🤔
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 itThis looks great! Would it be possible to extend this with svg output? It would be great for ballista ui
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 🤔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 itI think that if we just made it easier to use the existing formats, that would be a big win.
Can make
treea subcommand ofexplain, likeexplain tree <your sql>.Can make
treea subcommand ofexplain, likeexplain tree <your sql>.It looks like this is something that #15021 is going to handle.👀
I also just made
To clean up the display a bit
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:
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:
The output looks like
Items to complete
Information Completion for all
ExecutionPlansThe current implementation lacks detailed information for many physical plans.
Add rendering logic for missing operators (In every physical plan's
fmt_asfunction).treeexplain forFilterExec#15000DataSourceExec#15029treeexplain forProjectionExec#15023treeexplain forAggregateExec#15024treeexplain forLocalLimitExec#15025treeexplain forGlobalLimitExec#15026PartialSortExec#15064treeexplain forSortExec#15076RepartitionExecandWorkTableExec#15097treeexplain forBoundedWindowAggExecandWindowAggExec#15083SortPreservingMergeExec#15139treeexplain forHashJoinExec#15078treeexplain forNestedLoopJoinExec,CrossJoinExec,SortMergeJoinExecandSymmetricHashJoinExec#15080StreamingTableExec#15086treeexplain forValuesExec#15093treeexplain forForeignExecutionPlantreeexplain forJsonSink#15089ArrowFileSink#15112PlaceholderRowExec#15138CoalesceBatchesExec#15141CoalescePartitionsExec#15195New Features:
EXPLAINformats via SQL #15021treeexplain format #15020treeexplain mode #15107exprintreemode. #15238AggregateFunctionExpr#15252Process / Documentation
treeexplain in the user documentationTreeRenderin DisplayFormatType`treeexplain by defaultTest Coverage Expansion
Code Cleanup & Improvements
TODOs
explain treeformatting for longer lines / word wrap #15019treeexplain. #15098Make variables (e.g., indentation size, truncation thresholds) configurable:
Dead Code Removal
Remove or utilize the unused Coordinate struct: