Skip to content

Commit

Permalink
partition: fix index join probe side will locate partition error when…
Browse files Browse the repository at this point in the history
… it's a table range scan (#44414) (#44421)

close #43686
  • Loading branch information
ti-chi-bot authored Jun 6, 2023
1 parent e954f27 commit 3eb252d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4172,6 +4172,9 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte
locateKey[keyColOffsets[i]] = data
}
p, err := pt.GetPartitionByRow(e.ctx, locateKey)
if table.ErrNoPartitionForGivenValue.Equal(err) {
continue
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -4216,6 +4219,9 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte
locateKey[keyColOffsets[i]] = data
}
p, err := pt.GetPartitionByRow(e.ctx, locateKey)
if table.ErrNoPartitionForGivenValue.Equal(err) {
continue
}
if err != nil {
return nil, err
}
Expand Down
13 changes: 12 additions & 1 deletion executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3923,7 +3923,8 @@ func TestPartitionOnMissing(t *testing.T) {
tk.MustExec(`CREATE TABLE tt1 (
id INT NOT NULL,
listid INT,
name varchar(10)
name varchar(10),
primary key (listid) clustered
)
PARTITION BY LIST (listid) (
PARTITION p1 VALUES IN (1),
Expand Down Expand Up @@ -3955,4 +3956,14 @@ func TestPartitionOnMissing(t *testing.T) {

tk.MustQuery(`select /*+ inl_join(tt1)*/ count(*) from tt2
left join tt1 on tt1.listid=tt2.listid and tt1.id=tt2.id`).Check(testkit.Rows("5"))
tk.MustQuery(`select /*+ inl_join(tt1)*/ count(*) from tt2
left join tt1 on tt1.listid=tt2.listid`).Check(testkit.Rows("5"))
tk.MustQuery(`explain format = 'brief' select /*+ inl_join(tt1)*/ count(*) from tt2
left join tt1 on tt1.listid=tt2.listid`).Check(testkit.Rows(""+
"StreamAgg 1.00 root funcs:count(1)->Column#7",
"└─IndexJoin 5.00 root left outer join, inner:TableReader, outer key:onmissing.tt2.listid, inner key:onmissing.tt1.listid, equal cond:eq(onmissing.tt2.listid, onmissing.tt1.listid)",
" ├─IndexReader(Build) 5.00 root index:IndexFullScan",
" │ └─IndexFullScan 5.00 cop[tikv] table:tt2, index:idx_listid(listid) keep order:false",
" └─TableReader(Probe) 4.00 root partition:all data:TableRangeScan",
" └─TableRangeScan 4.00 cop[tikv] table:tt1 range: decided by [onmissing.tt2.listid], keep order:false"))
}

0 comments on commit 3eb252d

Please sign in to comment.