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)

close #53766
  • Loading branch information
dash12653 authored Oct 10, 2024
1 parent 9b1fa1c commit 0eccf79
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,11 @@ func (er *expressionRewriter) handleInSubquery(ctx context.Context, planCtx *exp
copy(join.OutputNames(), planCtx.plan.OutputNames())
copy(join.OutputNames()[planCtx.plan.Schema().Len():], agg.OutputNames())
join.AttachOnConds(expression.SplitCNFItems(checkCondition))
// set FullSchema and FullNames for this join
if left, ok := planCtx.plan.(*logicalop.LogicalJoin); ok && left.FullSchema != nil {
join.FullSchema = left.FullSchema
join.FullNames = left.FullNames
}
// Set join hint for this join.
if planCtx.builder.TableHints() != nil {
join.SetPreferredJoinTypeAndOrder(planCtx.builder.TableHints())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,8 @@ Projection_11 6.00 root 1->Column#18
└─Projection_17(Probe) 10000.00 root cast(test.t61a85298.col_71, double BINARY)->Column#19
└─TableReader_19 10000.00 root data:TableFullScan_18
└─TableFullScan_18 10000.00 cop[tikv] table:t61a85298 keep order:false, stats:pseudo
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
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,9 @@ FROM (
) AS derived_table
WHERE 16739493649928310215 MEMBER OF (derived_table.col_60767)
OR NOT (JSON_CONTAINS(derived_table.col_60767, '6019730272580550835'));

# 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));

0 comments on commit 0eccf79

Please sign in to comment.