Skip to content

Commit

Permalink
planner: merge FullSchema and FullNames of subplans when rewriting "i…
Browse files Browse the repository at this point in the history
…n (subquery)" to inner join (#54334) (#57036)

close #53766
  • Loading branch information
ti-chi-bot authored Oct 31, 2024
1 parent 6f0cb3b commit b2b6795
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
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

0 comments on commit b2b6795

Please sign in to comment.