-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
plan: return table dual when filter is false/null #7756
Conversation
Impose this check after constant propagation
/run-all-tests |
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.
lgtm
plan/rule_predicate_push_down.go
Outdated
@@ -34,6 +34,12 @@ func addSelection(p LogicalPlan, child LogicalPlan, conditions []expression.Expr | |||
return | |||
} | |||
conditions = expression.PropagateConstant(p.context(), conditions) | |||
// Return table dual when filter is constant false or null |
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.
add a .
at the end of this comment.
plan/rule_predicate_push_down.go
Outdated
@@ -55,6 +61,11 @@ func (p *LogicalSelection) PredicatePushDown(predicates []expression.Expression) | |||
retConditions, child := p.children[0].PredicatePushDown(append(p.Conditions, predicates...)) | |||
if len(retConditions) > 0 { | |||
p.Conditions = expression.PropagateConstant(p.ctx, retConditions) | |||
// Return table dual when filter is constant false or null |
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.
ditto
plan/rule_predicate_push_down.go
Outdated
@@ -375,3 +392,21 @@ func deriveOtherConditions(p *LogicalJoin, deriveLeft bool, deriveRight bool) (l | |||
} | |||
return | |||
} | |||
|
|||
// conds2TableDual build a LogicalTableDual if cond is constant false or null |
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.
s/ build/ builds
return nil | ||
} | ||
sc := p.context().GetSessionVars().StmtCtx | ||
if isTrue, err := con.Value.ToBool(sc); (err == nil && isTrue == 0) || con.Value.IsNull() { |
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.
Will it be possible that err != nil && con.Value.IsNull()
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 is possible, but the constant is a NULL
value, the err
should be ignored.
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.
LGTM
What problem does this PR solve?
Fix #7728
What is changed and how it works?
Add false/null check after constant propagation
Check List
Tests