feat: make StatisticsRegistry the default operator-statistics path#23651
Draft
asolimando wants to merge 5 commits into
Draft
feat: make StatisticsRegistry the default operator-statistics path#23651asolimando wants to merge 5 commits into
asolimando wants to merge 5 commits into
Conversation
…ontext walk Make StatisticsContext compute and cache ExtendedStatistics so custom statistics can propagate through the operator-statistics walk. Add compute_extended (returns Arc<ExtendedStatistics>); compute becomes a thin base-only view over it, keeping its Arc<Statistics> signature and all existing callers unchanged. Single-input operators transport a child's custom extensions unchanged (Extensions::merge_missing / ExtendedStatistics::merge_missing_extensions); multi-input operators forward nothing, deferring any combination to a StatisticsProvider. ExecutionPlan::statistics_from_inputs is unchanged.
…istics walk StatisticsContext::compute_extended consults the provider chain (with pre-resolved children) before each operator's statistics_from_inputs; StatisticsRegistry::compute delegates to it instead of recursing itself, and the built-in providers derive their base from the resolved children rather than re-walking. Collapse get_stats to one walk.
…istry flag The physical optimizer always consults the session's StatisticsRegistry; with no providers registered it is a no-op, so default behavior is unchanged. Deprecates the datafusion.optimizer.use_statistics_registry flag (now ignored with a warning; configs.md, information_schema, 55.0.0 upgrade guide). Rewire statistics_registry.slt to register the built-in providers via the test harness instead of the flag.
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #23651 +/- ##
=======================================
Coverage ? 80.65%
=======================================
Files ? 1086
Lines ? 366567
Branches ? 366567
=======================================
Hits ? 295655
Misses ? 53288
Partials ? 17624 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The statistics walk falls back to each operator's statistics_from_inputs when the provider chain delegates or is empty, so a terminal "default" provider is unnecessary now that the registry is the default path. Deprecate DefaultStatisticsProvider and drop it from the built-in chain; keep it for backward compatibility (removal would be a breaking API change).
…ats) Two runnable examples under datafusion-examples/examples/statistics, each showing a registry-driven plan flip via before/after EXPLAIN: - override: a provider corrects an intermediate join's row-count estimate with plain Statistics, flipping the outer join's build side. - custom_stats: a custom NDV sketch is attached at scans, merged across a join through the ExtendedStatistics extension map, and consumed to flip the plan - something a scalar distinct_count cannot express.
asolimando
force-pushed
the
asolimando/statistics-registry-default
branch
from
July 16, 2026 20:19
1f2d39d to
38d5bb1
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
StatisticsRegistry(#21483) was opt-in behinddatafusion.optimizer.use_statistics_registryand ran as a separate tree walk from the main statistics computation, so the two could disagree and the registry only reached code that explicitly consulted it. Since #23051 collapsed statistics traversal into a singleStatisticsContextwalk, the registry can just be folded into that walk instead. This makes it the default path: providers are consulted at each node before falling back to the operator'sstatistics_from_inputs, so there's one walk and the flag is no longer needed.What changes are included in this PR?
StatisticsContextwalk: the first provider that returnsComputedsets the node's stats, otherwise the walk falls back to the operator'sstatistics_from_inputs.join_selectionuses this walk.ExtendedStatistics(coreStatisticsplus a type-keyed extension map) internally; thestatistics_from_inputssignature is unchanged. Extensions are empty by default (the walk never forwards them, so a stale extension can't propagate silently); providers opt into propagation, e.g.PassthroughStatisticsProvideracross cardinality-preserving operators.StatisticsProvidergains a defaulted, partition-awarecompute_statistics_with_args(overall-only by default, delegates per partition so a partition-blind provider can't leak an overall estimate into one partition).use_statistics_registryis deprecated (kept but ignored, warns on use);configs.md,information_schema.slt, and the 55.0.0 upgrade guide are updated.DefaultStatisticsProvideris deprecated and dropped from the built-in provider chain; the walk's native fallback tostatistics_from_inputsmakes it redundant.datafusion-examples/examples/statistics/, each with a before/after EXPLAIN flip: a row-count override provider (coreStatistics) and a custom NDV-sketch provider carried through the extension map.Are these changes tested?
Unit tests in
operator_statistics/statistics(provider chaining, partition-aware providers, per-partitionUnionExecwith a registry), thestatistics_registry.sltfile, and both examples. Full extended suite passes locally.Are there any user-facing changes?
datafusion.optimizer.use_statistics_registryis deprecated and ignored (accepted with a warning, removed later). Default behavior is unchanged: no providers registered means the registry is a no-op. See the 55.0.0 upgrade guide.StatisticsProvidergains a defaultedcompute_statistics_with_args, andDefaultStatisticsProvideris deprecated (not removed). For default behavior register nothing, orStatisticsRegistry::default_with_builtin_providers()for the built-in providers. See the 55.0.0 upgrade guide.Disclaimer: I used AI to assist in the code generation, I have manually reviewed the output and it matches my intention and understanding.