-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix correctness bug in EffectivePredicateExtractor #23674
Conversation
92315e0
to
dd3ff3a
Compare
to not pull up expressions only referring to constants
dd3ff3a
to
c88ea85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice discovery. Thanks!
Should we add a test from #23660? |
effectiveConjuncts.add(rewritten); | ||
} | ||
// If equality inference has reduced the predicate to an expression referring to only constants, it does not make sense to pull this predicate up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit confused here, as to why do we have the condition to skip if rewritten has variable references? What if the variable reference is pointing to a constant in some project below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess if it is below, then correctness should already be correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If rewritten
has variable references that are in(variables)
we do not skip them and pull them up (by adding them to effectiveConjuncts
. The problem here is that EqaulityInference
is designed to rewrite expressions to just constants (see test), even though, technically this expression does not refer to any variables
However, if the rewritten
expression has no variable references, le.g mod(10,5)=1
- this predicate should not be pulled up, to say, a Join node, because it has no references in the outputs of the Join and cannot impact any predicate inferencing there
"SELECT regionkey, (select name from nation where false) from region", | ||
"SELECT regionkey, NULL from region"); | ||
assertQuery( | ||
"SELECT regionkey, (select name from nation where nationkey = 5 and mod(nationkey,5) = 1) from region", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaystarshot The query used here is logically identical to one from the #23660 issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this current only tests execution and not result expectations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It asserts that results are identical to those from SELECT regionkey, NULL from region
effectiveConjuncts.add(rewritten); | ||
} | ||
// If equality inference has reduced the predicate to an expression referring to only constants, it does not make sense to pull this predicate up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If rewritten
has variable references that are in(variables)
we do not skip them and pull them up (by adding them to effectiveConjuncts
. The problem here is that EqaulityInference
is designed to rewrite expressions to just constants (see test), even though, technically this expression does not refer to any variables
However, if the rewritten
expression has no variable references, le.g mod(10,5)=1
- this predicate should not be pulled up, to say, a Join node, because it has no references in the outputs of the Join and cannot impact any predicate inferencing there
Description
Fixes #23660
During predicate pushdown through a Join, we were
FALSE
, but now is pushed down to both sides of the joinThis results in the optimizer Incorrectly assuming no results will be produced
Fix
Pulling up expressions happens in
EffectivePredicateExtractor#pullExpressionThroughVariables
. This was modified to stop pulling up expressions that only refer to constants since this is logically incorrectTest Plan
Contributor checklist
Release Notes