Skip to content
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
15 changes: 7 additions & 8 deletions pkg/planner/core/operator/logicalop/logical_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,23 +1081,22 @@ func (p *LogicalJoin) ExtractUsedCols(parentUsedCols []*expression.Column) (left
rChild := p.Children()[1]
lSchema := lChild.Schema()
rSchema := rChild.Schema()
var lFullSchema, rFullSchema *expression.Schema
// parentused col = t2.a
// leftChild schema = t1.a(t2.a) + and others
// rightChild schema = t3 related + and others
if join, ok := lChild.(*LogicalJoin); ok {
if join.FullSchema != nil {
lSchema = join.FullSchema
}
lFullSchema = join.FullSchema
}
if join, ok := rChild.(*LogicalJoin); ok {
if join.FullSchema != nil {
rSchema = join.FullSchema
}
rFullSchema = join.FullSchema
}
for _, col := range parentUsedCols {
if lSchema != nil && lSchema.Contains(col) {
if (lSchema != nil && lSchema.Contains(col)) ||
(lFullSchema != nil && lFullSchema.Contains(col)) {
leftCols = append(leftCols, col)
} else if rSchema != nil && rSchema.Contains(col) {
} else if (rSchema != nil && rSchema.Contains(col)) ||
(rFullSchema != nil && rFullSchema.Contains(col)) {
rightCols = append(rightCols, col)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,3 +910,40 @@ IndexLookUp 1.00 root
└─Selection(Probe) 1.00 cop[tikv] eq(test_59427.t.a, 1)
└─TableRowIDScan 10.00 cop[tikv] table:tt keep order:false, stats:pseudo
drop database if exists test_59427;
drop table if exists t1,t2,t3,t4,t5;
create table t1(a int, b int, c int, d int, e int);
create table t2(a int, b int, c int, d int, e int);
create table t3(a int, b int, c int, d int, e int);
create table t4(a int, b int, c int, d int, e int);
create table t5(a int, b int, c int, d int, e int);
explain format = brief select tmp4.b
from t1 join t2 on t1.a = t2.b
join t3 on t1.b = t3.b
left join
(select a, b, c, (row_number() over (partition by b order by e asc)) from t4) tmp4 on tmp4.b = t2.c and tmp4.c = t3.c
join t5 on t5.a = t1.e;
id estRows task access object operator info
HashJoin 19472.71 root inner join, equal:[eq(test.t5.a, test.t1.e)]
├─TableReader(Build) 9990.00 root data:Selection
│ └─Selection 9990.00 cop[tikv] not(isnull(test.t5.a))
│ └─TableFullScan 10000.00 cop[tikv] table:t5 keep order:false, stats:pseudo
└─HashJoin(Probe) 15578.17 root left outer join, left side:HashJoin, equal:[eq(test.t2.c, test.t4.b) eq(test.t3.c, test.t4.c)]
├─Selection(Build) 7992.00 root not(isnull(test.t4.c))
│ └─Shuffle 9990.00 root execution info: concurrency:100, data sources:[TableReader]
│ └─Window 9990.00 root row_number()->Column#26 over(partition by test.t4.b order by test.t4.e rows between current row and current row)
│ └─Sort 9990.00 root test.t4.b, test.t4.e
│ └─ShuffleReceiver 9990.00 root
│ └─TableReader 9990.00 root data:Selection
│ └─Selection 9990.00 cop[tikv] not(isnull(test.t4.b))
│ └─TableFullScan 10000.00 cop[tikv] table:t4 keep order:false, stats:pseudo
└─HashJoin(Probe) 15578.17 root inner join, equal:[eq(test.t1.b, test.t3.b)]
├─HashJoin(Build) 12462.54 root inner join, equal:[eq(test.t1.a, test.t2.b)]
│ ├─TableReader(Build) 9990.00 root data:Selection
│ │ └─Selection 9990.00 cop[tikv] not(isnull(test.t2.b))
│ │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo
│ └─TableReader(Probe) 9970.03 root data:Selection
│ └─Selection 9970.03 cop[tikv] not(isnull(test.t1.a)), not(isnull(test.t1.b)), not(isnull(test.t1.e))
│ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo
└─TableReader(Probe) 9990.00 root data:Selection
└─Selection 9990.00 cop[tikv] not(isnull(test.t3.b))
└─TableFullScan 10000.00 cop[tikv] table:t3 keep order:false, stats:pseudo
13 changes: 13 additions & 0 deletions tests/integrationtest/t/planner/core/issuetest/planner_issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,16 @@ explain format = brief select * from test_59427.t as tt use index (ib) where a =
explain format = brief select /*+ use_index(test_59427.tt, ib) */ * from test_59427.t as tt where a = 1 and b = 1;
drop database if exists test_59427;

# TestIssue60692
drop table if exists t1,t2,t3,t4,t5;
create table t1(a int, b int, c int, d int, e int);
create table t2(a int, b int, c int, d int, e int);
create table t3(a int, b int, c int, d int, e int);
create table t4(a int, b int, c int, d int, e int);
create table t5(a int, b int, c int, d int, e int);
explain format = brief select tmp4.b
from t1 join t2 on t1.a = t2.b
join t3 on t1.b = t3.b
left join
(select a, b, c, (row_number() over (partition by b order by e asc)) from t4) tmp4 on tmp4.b = t2.c and tmp4.c = t3.c
join t5 on t5.a = t1.e;