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: merge FullSchema and FullNames of subplans when rewriting "in (subquery)" to inner join (#54334) #57036

Merged
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
5 changes: 5 additions & 0 deletions cmd/explaintest/r/planner_issue.result
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ IndexReader 250.00 root index:Selection
select * from t1 use index (ia) where a like 'xxx_';
a
xxx
drop table if exists t0, t1;
CREATE TABLE t0(c0 int);
CREATE TABLE t1(c0 int);
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
c0 c0
6 changes: 6 additions & 0 deletions cmd/explaintest/t/planner_issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ select *,length(a) from t1 where a like '测试 %';
select *,length(a) from t1 where a like '测试';
explain format = brief select * from t1 use index (ia) where a like 'xxx_';
select * from t1 use index (ia) where a like 'xxx_';

# TestIssue53766
drop table if exists t0, t1;
CREATE TABLE t0(c0 int);
CREATE TABLE t1(c0 int);
SELECT t0.c0, t1.c0 FROM t0 NATURAL JOIN t1 WHERE '1' AND (t0.c0 IN (SELECT c0 FROM t0));
5 changes: 5 additions & 0 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,11 @@ func (er *expressionRewriter) handleInSubquery(ctx context.Context, v *ast.Patte
copy(join.names, er.p.OutputNames())
copy(join.names[er.p.Schema().Len():], agg.OutputNames())
join.AttachOnConds(expression.SplitCNFItems(checkCondition))
// set FullSchema and FullNames for this join
if left, ok := er.p.(*LogicalJoin); ok && left.fullSchema != nil {
join.fullSchema = left.fullSchema
join.fullNames = left.fullNames
}
// Set join hint for this join.
if er.b.TableHints() != nil {
join.setPreferredJoinTypeAndOrder(er.b.TableHints())
Expand Down