Add ExpressionAnalyzer for pluggable expression-level statistics estimation#21122
Draft
asolimando wants to merge 2 commits intoapache:mainfrom
Draft
Add ExpressionAnalyzer for pluggable expression-level statistics estimation#21122asolimando wants to merge 2 commits intoapache:mainfrom
asolimando wants to merge 2 commits intoapache:mainfrom
Conversation
Introduce ExpressionAnalyzer, a chain-of-responsibility framework for expression-level statistics estimation (NDV, selectivity, min/max). Framework: - ExpressionAnalyzer trait with registry parameter for chain delegation - ExpressionAnalyzerRegistry to chain analyzers (first Computed wins) - DefaultExpressionAnalyzer: Selinger-style estimation for columns, literals, binary expressions, NOT, boolean predicates Integration: - ExpressionAnalyzerRegistry stored in SessionState, initialized once - ProjectionExprs stores optional registry (non-breaking, no signature changes to project_statistics) - ProjectionExec sets registry via Projector, injected by planner - FilterExec uses registry for selectivity when interval analysis cannot handle the predicate - Custom nodes get builtin analyzer as fallback when registry is absent
- Regenerate configs.md for new enable_expression_analyzer option - Add enable_expression_analyzer to information_schema.slt expected output - Fix unresolved doc links to SessionState and DefaultExpressionAnalyzer (cross-crate references use backticks instead of doc links) - Simplify config description
322b97f to
f101c51
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?
Part of #21120 (framework + projection/filter integration)
Rationale for this change
DataFusion currently loses expression-level statistics when computing plan metadata. Projected expressions that aren't bare columns or literals get unknown statistics, and filter selectivity falls back to a hardcoded 20% when interval analysis cannot handle the predicate. There is also no extension point for users to provide statistics for their own UDFs.
This PR introduces ExpressionAnalyzer, a pluggable chain-of-responsibility framework that addresses these gaps. It follows the same extensibility pattern used elsewhere in DataFusion (ExprPlanner, OptimizerRule).
Addresses reviewer feedback from #19957: chain delegation, SessionState integration, own folder.
What changes are included in this PR?
ExpressionAnalyzertrait withregistryparameter for chain delegationExpressionAnalyzerRegistryto chain analyzers (firstComputedwins)DefaultExpressionAnalyzer: Selinger-style estimation for columns, literals, binary expressions (AND/OR/NOT/comparisons), arithmeticExpressionAnalyzerRegistrystored inSessionState, injected intoProjectionExecandFilterExecby the plannerProjectionExprsuses registry to estimate NDV, min/max, and null fraction through projected expressionsFilterExecuses registry selectivity as fallback whencheck_supportreturns falseoptimizer.enable_expression_analyzer(default false) to opt in; zero behavior change when disabledAre these changes tested?
test_project_statistics_with_expression_analyzer)Are there any user-facing changes?
New public API (purely additive, non-breaking):
ExpressionAnalyzertrait andExpressionAnalyzerRegistryindatafusion-physical-exprSessionState::expression_analyzer_registry()getterSessionStateBuilder::with_expression_analyzer_registry()setterProjectionExprs::with_expression_analyzer_registry()setterFilterExecBuilder::with_expression_analyzer_registry()setterProjectionExec::with_expression_analyzer_registry()setterdatafusion.optimizer.enable_expression_analyzerNo breaking changes. Default behavior is unchanged (config defaults to false).
Disclaimer: I used AI to assist in the code generation, I have manually reviewed the output and it matches my intention and understanding.