feat: add pgjson format support for EXPLAIN ANALYZE#21767
Draft
adriangb wants to merge 1 commit intoapache:mainfrom
Draft
feat: add pgjson format support for EXPLAIN ANALYZE#21767adriangb wants to merge 1 commit intoapache:mainfrom
adriangb wants to merge 1 commit intoapache:mainfrom
Conversation
af1be1a to
b4c739f
Compare
Extend the existing `FORMAT pgjson` option so that it also renders
`EXPLAIN ANALYZE` output as PostgreSQL-style JSON, suitable for
visualizers such as Dalibo and PEV2.
Each physical operator becomes a JSON object carrying:
- `Node Type` — `ExecutionPlan::name()`
- `Details` — the one-line `DisplayAs::Default` rendering
- `Actual Rows` / `Actual Total Time` — PG-canonical metric keys
populated from `output_rows` / `elapsed_compute`
- `Extras` — remaining DataFusion metrics keyed by their native name
- `Plans` — child nodes
The existing logical-plan pgjson path, metric filtering config
(`analyze_categories`), and indent-format behavior are unchanged.
`Tree` and `Graphviz` with `ANALYZE` remain unsupported with a clear
error.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
b4c739f to
5fc8a84
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
DataFusion already emits PostgreSQL JSON (pgjson) for logical plans via
EXPLAIN (FORMAT pgjson) .... This PR extends that support toEXPLAIN ANALYZEso the physical plan, along with live execution metrics, can be fed into pgjson visualizers such as Dalibo and PEV2.Today,
EXPLAIN ANALYZE FORMAT pgjsonis explicitly rejected in the planner with"EXPLAIN ANALYZE with FORMAT is not supported". With this PR the restriction is lifted for pgjson.What changes are included in this PR?
format: ExplainFormatfield to the logicalAnalyzenode and the physicalAnalyzeExecoperator, threaded through SQL parsing, logical planning, and physical planning.EXPLAIN ANALYZE FORMAT pgjson <stmt>.TreeandGraphvizwithANALYZEstill error with a clear message (out of scope for this PR).DisplayableExecutionPlan::pgjson()and a newPgJsonExecutionPlanVisitorthat mirror the logical-planPgJsonVisitor. Per-node output includes:Node Type—ExecutionPlan::name()Details— the one-lineDisplayAs::DefaultrenderingActual Rows/Actual Total Time— PG-canonical metric keys populated fromoutput_rows/elapsed_compute(emitted as float milliseconds; note DataFusion records compute time, not wall time)Extras— remaining DataFusion metrics keyed by their native namePlans— child nodesset_summary()builder soAnalyzeExeccan attachTotal RowsandDurationat the root in verbose mode.analyze_level/analyze_categoriesconfig exactly asindent()does.Are these changes tested?
datafusion/physical-plan/src/display.rs:pgjson_renders_plan_without_metricspgjson_includes_summary_when_setpgjson_snapshot_of_sample_plan(insta snapshot)datafusion/sqllogictest/test_files/explain_analyze.slt:EXPLAIN ANALYZE FORMAT pgjsonwithanalyze_categories = 'none'EXPLAIN ANALYZE FORMAT treeandEXPLAIN ANALYZE FORMAT graphvizcargo clippy --all-targets --all-features -- -D warningsclean on the touched crates;cargo fmt --allclean.Are there any user-facing changes?
Yes — new syntax is accepted:
No existing behavior changes: the default (
EXPLAIN ANALYZE ...with noFORMAT) still emits the indent-format plan with metrics, andEXPLAIN (FORMAT pgjson) ...on the logical plan is unchanged.🤖 Generated with Claude Code