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)
  • Loading branch information
fzhedu authored Apr 16, 2020
1 parent 39cc893 commit e3b635e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1579,3 +1579,23 @@ func (s *testPlanSuite) TestConflictedJoinTypeHints(c *C) {
c.Assert(join.hintInfo, IsNil)
c.Assert(join.preferJoinType, Equals, uint(0))
}

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"
ctx := context.TODO()
stmt, err := s.ParseOneStmt(sql, "", "")
c.Assert(err, IsNil)
Preprocess(s.ctx, stmt, s.is)
builder := NewPlanBuilder(MockContext(), s.is, &hint.BlockHintProcessor{})
p, err := builder.Build(ctx, stmt)
c.Assert(err, IsNil)
p, err = logicalOptimize(ctx, 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 @@ -316,6 +316,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 e3b635e

Please sign in to comment.