Instrument plan creation #36
Merged
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?
Closes #32 and #35.
Rationale for this change
See linked issues. Users have no visibility into DataFusion's planning pipeline, making it hard to identify optimization bottlenecks or understand which rules actually affect the plan.
What changes are included in this PR?
This PR instruments the entire query planning pipeline: analyzer, logical optimizer, physical plan creation, and physical optimizer.
Each phase gets a parent span (
analyze_logical_plan,optimize_logical_plan,optimize_physical_plan) that groups individual rule executions. Rules that actually modify the plan are marked with a(modified)suffix in their span name, and the phase span records which rules were effective. For the logical optimizer, pass numbers are tracked since it can run multiple iterations.The
RuleInstrumentationOptionstype controls verbosity:Disabledfor no instrumentation,PhaseOnlyfor just the phase spans, orFullfor phase spans plus individual rule spans. There's also an option to include unified diffs showing exactly what changed.Expensive operations like plan formatting and diffing are skipped when spans are disabled (lazy instrumentation).
New macros (
instrument_rules_with_info_spans!, etc.) make it easy to instrument aSessionState. When physical optimizer instrumentation is enabled, the query planner is automatically wrapped to trace physical plan creation.Example Trace
Usage
For finer control, use the builder:
Or for less verbose traces, use phase-only instrumentation:
Are these changes tested?
Yes, the integration test suite now enables rule instrumentation and all snapshot tests have been updated to capture the new spans.
Are there any user-facing changes?
New public APIs:
RuleInstrumentationOptions,RuleInstrumentationOptionsBuilder, and theinstrument_rules_with_*_spans!macros. No breaking changes.