Skip to content

Commit

Permalink
cherry pick pingcap#16444 to release-2.1
Browse files Browse the repository at this point in the history
Signed-off-by: sre-bot <sre-bot@pingcap.com>
  • Loading branch information
fzhedu authored and sre-bot committed Apr 16, 2020
1 parent 8f2afff commit 1708905
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
69 changes: 69 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2215,3 +2215,72 @@ func (s *testPlanSuite) TestFastPlanContextTables(c *C) {
}
}
}
<<<<<<< HEAD
=======

func (s *testPlanSuite) TestUpdateEQCond(c *C) {
defer testleak.AfterTest(c)()
tests := []struct {
sql string
best string
}{
{
sql: "select t1.a from t t1, t t2 where t1.a = t2.a+1",
best: "Join{DataScan(t1)->DataScan(t2)->Projection}(test.t.a,Column#25)->Projection",
},
}
ctx := context.TODO()
for i, tt := range tests {
comment := Commentf("case:%v sql:%s", i, tt.sql)
stmt, err := s.ParseOneStmt(tt.sql, "", "")
c.Assert(err, IsNil, comment)
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)
c.Assert(ToString(p), Equals, tt.best, comment)
}
}

func (s *testPlanSuite) TestConflictedJoinTypeHints(c *C) {
defer testleak.AfterTest(c)()
sql := "select /*+ INL_JOIN(t1) HASH_JOIN(t1) */ * from t t1, t t2 where t1.e = t2.e"
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)
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)
}
>>>>>>> e3b635e... planner: cannot simply outer join if a predicate just refers to the outer table (#16444)
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 1708905

Please sign in to comment.