-
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
Changes from 5 commits
ac819bc
8a65cbd
7139464
ab70184
633d6da
1a7ef88
acf1818
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
dual := conds2TableDual(child, conditions) | ||
if dual != nil { | ||
p.Children()[chIdx] = dual | ||
return | ||
} | ||
selection := LogicalSelection{Conditions: conditions}.init(p.context()) | ||
selection.SetChildren(child) | ||
p.Children()[chIdx] = selection | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
dual := conds2TableDual(p, p.Conditions) | ||
if dual != nil { | ||
return nil, dual | ||
} | ||
return nil, p | ||
} | ||
return nil, child | ||
|
@@ -129,7 +140,13 @@ func (p *LogicalJoin) PredicatePushDown(predicates []expression.Expression) (ret | |
tempCond = append(tempCond, p.OtherConditions...) | ||
tempCond = append(tempCond, predicates...) | ||
tempCond = expression.ExtractFiltersFromDNFs(p.ctx, tempCond) | ||
equalCond, leftPushCond, rightPushCond, otherCond = extractOnCondition(expression.PropagateConstant(p.ctx, tempCond), leftPlan, rightPlan, true, true) | ||
tempCond = expression.PropagateConstant(p.ctx, tempCond) | ||
// Return table dual when filter is constant false or null | ||
dual := conds2TableDual(p, tempCond) | ||
if dual != nil { | ||
return ret, dual | ||
} | ||
equalCond, leftPushCond, rightPushCond, otherCond = extractOnCondition(tempCond, leftPlan, rightPlan, true, true) | ||
p.LeftConditions = nil | ||
p.RightConditions = nil | ||
p.EqualConditions = equalCond | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. s/ build/ builds |
||
func conds2TableDual(p LogicalPlan, conds []expression.Expression) LogicalPlan { | ||
if len(conds) != 1 { | ||
return nil | ||
} | ||
con, ok := conds[0].(*expression.Constant) | ||
if !ok { | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Will it be possible that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible, but the constant is a |
||
dual := LogicalTableDual{}.init(p.context()) | ||
dual.SetSchema(p.Schema()) | ||
return dual | ||
} | ||
return nil | ||
} |
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.