Skip to content
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

planner: cannot simply outer join if a predicate just refers to the outer table (#16444) #16494

Merged
merged 2 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1578,3 +1578,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