[SPARK-57437][SQL] Infer additional constraints by substituting attribute-to-literal bindings#56499
Open
xumingming wants to merge 1 commit into
Open
Conversation
…bute-to-literal bindings When a predicate binds an attribute to a literal (e.g. a.pt = '20260610') and another predicate references that attribute (e.g. b.pt >= f(a.pt)), Catalyst previously did not exploit the literal binding to derive a simpler, pushable predicate. This change extends ConstraintHelper.inferAdditionalConstraints with a second pass that: 1. Collects Attribute = Literal bindings from the constraint set. 2. Substitutes the literal into non-equality predicates that reference those attributes. 3. Adds the resulting deterministic expressions as new inferred constraints. After constant folding, the inferred predicates can be pushed into scans as partition filters, avoiding full-table scans in cases where only a small subset of partitions can match.
Author
|
@cloud-fan Can you help taking a look at this PR? |
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.
What changes were proposed in this pull request?
When a predicate binds an attribute to a literal (e.g. a.pt = '20260610') and another predicate references that attribute (e.g. b.pt >= f(a.pt)), Catalyst previously did not exploit the literal binding to derive a simpler, pushable predicate.
Here table b is full scaned, thus very bad performance.
This change extends ConstraintHelper.inferAdditionalConstraints with a second pass that:
After constant folding, the inferred predicates can be pushed into scans as partition filters, avoiding full-table scans in cases where only a small subset of partitions can match.
Why are the changes needed?
Currently query of the following pattern causes full table scan for table b:
With this optimization table b can get very good partition pruning.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added unit tests.
Was this patch authored or co-authored using generative AI tooling?
No.