Skip to content

Commit d3b442a

Browse files
committed
push filters down into join condition
1 parent b0670cf commit d3b442a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

sql/analyzer/pushdown.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,5 +339,14 @@ func removePushedDownPredicates(ctx *sql.Context, a *Analyzer, node *plan.Filter
339339
unhandled,
340340
)
341341

342+
if joinChild, ok := node.Child.(*plan.JoinNode); ok && !joinChild.Op.IsOuter() {
343+
if joinChild.Op.IsCross() {
344+
return plan.NewInnerJoin(joinChild.Left(), joinChild.Right(), expression.JoinAnd(unhandled...))
345+
}
346+
unhandled = append(unhandled, joinChild.Filter)
347+
joinChild.Filter = expression.JoinAnd(unhandled...)
348+
return joinChild
349+
}
350+
342351
return plan.NewFilter(expression.JoinAnd(unhandled...), node.Child)
343352
}

sql/plan/join.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ const (
6868
JoinTypeLateralRight // LateralLeftJoin
6969
)
7070

71+
func (i JoinType) IsOuter() bool {
72+
return i.IsLeftOuter() || i.IsRightOuter() || i.IsFullOuter()
73+
}
74+
7175
func (i JoinType) IsLeftOuter() bool {
7276
switch i {
7377
case JoinTypeLeftOuter, JoinTypeLeftOuterExcludeNulls, JoinTypeLeftOuterLookup, JoinTypeLeftOuterHash, JoinTypeLeftOuterHashExcludeNulls, JoinTypeLeftOuterMerge, JoinTypeLeftOuterRangeHeap:

0 commit comments

Comments
 (0)