From a69ddf1879da0fb42f9ce4e11f2d05e6cbc49d29 Mon Sep 17 00:00:00 2001 From: Arenatlx <314806019@qq.com> Date: Mon, 5 Jun 2023 19:15:40 +0800 Subject: [PATCH] partition: fix index join probe side will locate partition error when it's a table range scan (#44414) close pingcap/tidb#43686 --- executor/builder.go | 6 ++++++ executor/test/partitiontest/partition_test.go | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/executor/builder.go b/executor/builder.go index a602d34b13ac7..45b7f046e88a8 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -4276,6 +4276,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 } @@ -4320,6 +4323,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 } diff --git a/executor/test/partitiontest/partition_test.go b/executor/test/partitiontest/partition_test.go index b710924a6a1b6..d9614cd808ec3 100644 --- a/executor/test/partitiontest/partition_test.go +++ b/executor/test/partitiontest/partition_test.go @@ -459,7 +459,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), @@ -491,4 +492,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")) }