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

close #51560
  • Loading branch information
ti-chi-bot authored May 28, 2024
1 parent ff05c7a commit a8087f7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
8 changes: 0 additions & 8 deletions pkg/planner/core/rule_predicate_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,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
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,31 @@ id value
3 0
4 4
5 5
create table A(a int primary key, b int);
create table B(b int primary key);
create table C(c int primary key, b int);
insert into A values (2, 1), (3, 2);
insert into B values (1), (2);
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);
b
1
2
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);
b
1
2
drop table if exists t0, t1;
CREATE TABLE t0(c0 NUMERIC);
CREATE TABLE t1(c0 NUMERIC);
Expand Down
Binary file not shown.
26 changes: 26 additions & 0 deletions tests/integrationtest/t/planner/core/issuetest/planner_issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ where test2.id in
);
select * from test2;

# https://github.com/pingcap/tidb/issues/51560
create table A(a int primary key, b int);
create table B(b int primary key);
create table C(c int primary key, b int);

insert into A values (2, 1), (3, 2);
insert into B values (1), (2);

# Returns data as expected
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);

# Returns the same.
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);

# https://github.com/pingcap/tidb/issues/49109
drop table if exists t0, t1;
CREATE TABLE t0(c0 NUMERIC);
Expand Down

0 comments on commit a8087f7

Please sign in to comment.