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

Merged
merged 3 commits into from
Oct 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,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));