optimizer: extract null-restriction evaluator and add syntactic fast-path with focused tests#21289
Open
kosiew wants to merge 6 commits intoapache:mainfrom
Open
optimizer: extract null-restriction evaluator and add syntactic fast-path with focused tests#21289kosiew wants to merge 6 commits intoapache:mainfrom
kosiew wants to merge 6 commits intoapache:mainfrom
Conversation
Implement syntactic null-restriction checks in a new file. Introduce SyntacticNullRestriction enum and syntactic_null_restriction_check function. Modify utils.rs for early returns and fast-path evaluation to improve performance.
Ensure predicates always pass through the join-column subset guard before any fast-path decision. Strengthen tests with a bare non-join column regression case and modify the parity test to compare the syntactic helper against direct authoritative evaluation. Update module documentation to accurately describe the enum-based return values.
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
This PR extracts and formalizes the null-restriction evaluation logic into a dedicated utility module to improve clarity, performance, and reviewability.
Previously, null-restriction determination relied solely on evaluating physical expressions, which is more expensive and harder to reason about in isolation. Additionally, the logic was embedded in a broader set of changes, making it difficult to review independently.
This change introduces a conservative syntactic fast path that can determine null-restriction behavior for common predicate shapes without executing expressions. This improves optimizer efficiency while maintaining correctness by falling back to the authoritative evaluation path when needed.
The PR also explicitly guards against mixed-reference predicates (those referencing columns outside the provided join-column set), ensuring they are treated conservatively as non-restricting to avoid incorrect pruning.
What changes are included in this PR?
Introduced new module
utils/null_restriction.rscontaining:SyntacticNullRestrictionenumUpdated
is_restrict_null_predicateinutils.rsto:Improved internal documentation explaining:
Added focused unit tests:
Are these changes tested?
Yes.
This PR includes comprehensive unit tests that:
These tests help prevent regressions and document expected behavior.
Benchmark
Below are the benchmark results, using the modified #21029 benchmark
Are there any user-facing changes?
No.
This change is internal to the optimizer and does not modify public APIs or user-visible behavior. It improves performance and maintainability without altering query results.
LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated content has been manually reviewed and tested.