From 3eb252d0737ef0432eea2955ebeb1b89e0da68f2 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Tue, 6 Jun 2023 11:45:40 +0800 Subject: [PATCH] partition: fix index join probe side will locate partition error when it's a table range scan (#44414) (#44421) close pingcap/tidb#43686 --- executor/builder.go | 6 ++++++ executor/partition_table_test.go | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/executor/builder.go b/executor/builder.go index a99d1428fa48..77e474aa63ec 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -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 } @@ -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 } diff --git a/executor/partition_table_test.go b/executor/partition_table_test.go index e398733be62c..16d5e30ee9eb 100644 --- a/executor/partition_table_test.go +++ b/executor/partition_table_test.go @@ -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), @@ -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")) }