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: fix the issue about simplify outer join to inner join | tidb-test=pr/2313 #51750

Merged
merged 1 commit into from
Mar 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -335,3 +335,28 @@ 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
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 @@ -186,3 +186,29 @@ where test2.id in
select * from v1
);
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);