Skip to content

Commit

Permalink
planner: fix the issue about simplify outer join to inner join (#51750)…
Browse files Browse the repository at this point in the history
… (#52057)

close #51560
  • Loading branch information
ti-chi-bot committed Mar 25, 2024
1 parent cb2c200 commit 4fd9e85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion planner/core/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ go_test(
srcs = ["planner_issue_test.go"],
flaky = True,
race = "on",
shard_count = 6,
shard_count = 7,
deps = ["//testkit"],
)
15 changes: 15 additions & 0 deletions planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,18 @@ FROM
LEFT JOIN tmp3 c2 ON c2.id = '1'
LEFT JOIN tmp3 c3 ON c3.id = '1';`).Check(testkit.Rows("1 1", "1 1"))
}

func TestIssue51560(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists A, B, C")
tk.MustExec("create table A(a int primary key, b int);")
tk.MustExec("create table B(b int primary key);")
tk.MustExec("create table C(c int primary key, b int);")
tk.MustExec("insert into A values (2, 1), (3, 2);")
tk.MustExec("insert into B values (1), (2);")

tk.MustQuery("select b.b from A a left join (B b left join C c on b.b = c.b) on b.b = a.b where a.a in (2, 3);").Sort().Check(testkit.Rows("1", "2"))
tk.MustQuery("select b.b from A a left join (B b left join C c on b.b = c.b) on b.b = a.b where a.a in (2, 3, null);").Sort().Check(testkit.Rows("1", "2"))
}
8 changes: 0 additions & 8 deletions planner/core/rule_predicate_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,6 @@ func simplifyOuterJoin(p *LogicalJoin, predicates []expression.Expression) {
innerTable, outerTable = outerTable, innerTable
}

// first simplify embedded outer join.
if innerPlan, ok := innerTable.(*LogicalJoin); ok {
simplifyOuterJoin(innerPlan, predicates)
}
if outerPlan, ok := outerTable.(*LogicalJoin); ok {
simplifyOuterJoin(outerPlan, predicates)
}

if p.JoinType == InnerJoin {
return
}
Expand Down

0 comments on commit 4fd9e85

Please sign in to comment.