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
… (#52079)

close #51560
  • Loading branch information
ti-chi-bot committed Apr 16, 2024
1 parent c4a9d9b commit b955b70
Show file tree
Hide file tree
Showing 3 changed files with 15 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 = 10,
shard_count = 11,
deps = ["//testkit"],
)
14 changes: 14 additions & 0 deletions planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ func TestIssue48969(t *testing.T) {
tk.MustQuery("select * from test2").Check(testkit.Rows("1 0", "2 0", "3 0", "4 4", "5 5"))
}

func TestIssue51670(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
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);")
// The two should return the same result set.
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"))
}

func TestIssue50614(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
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 @@ -394,14 +394,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 b955b70

Please sign in to comment.