Skip to content

Commit

Permalink
planner: cannot simply outer join if a predicate just refers to the o…
Browse files Browse the repository at this point in the history
…uter table (#16444) (#16491)
  • Loading branch information
sre-bot authored Apr 20, 2020
1 parent 8f2afff commit 71dc882
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2215,3 +2215,26 @@ func (s *testPlanSuite) TestFastPlanContextTables(c *C) {
}
}
}

func (s *testPlanSuite) TestSimplyOuterJoinWithOnlyOuterExpr(c *C) {
defer testleak.AfterTest(c)()
sql := "select * from t t1 right join t t0 ON TRUE where CONCAT_WS(t0.e=t0.e, 0, NULL) IS NULL"
stmt, err := s.ParseOneStmt(sql, "", "")
c.Assert(err, IsNil)
Preprocess(s.ctx, stmt, s.is, false)
builder := &planBuilder{
ctx: mockContext(),
is: s.is,
colMapper: make(map[*ast.ColumnNameExpr]int),
}
p, err := builder.build(stmt)
c.Assert(err, IsNil)
p, err = logicalOptimize(builder.optFlag, p.(LogicalPlan))
c.Assert(err, IsNil)
proj, ok := p.(*LogicalProjection)
c.Assert(ok, IsTrue)
join, ok := proj.Children()[0].(*LogicalJoin)
c.Assert(ok, IsTrue)
// previous wrong JoinType is InnerJoin
c.Assert(join.JoinType, Equals, RightOuterJoin)
}
4 changes: 4 additions & 0 deletions planner/core/rule_predicate_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ func simplifyOuterJoin(p *LogicalJoin, predicates []expression.Expression) {
// then simplify embedding outer join.
canBeSimplified := false
for _, expr := range predicates {
// avoid the case where the expr only refers to the schema of outerTable
if expression.ExprFromSchema(expr, outerTable.Schema()) {
continue
}
isOk := isNullRejected(p.ctx, innerTable.Schema(), expr)
if isOk {
canBeSimplified = true
Expand Down

0 comments on commit 71dc882

Please sign in to comment.