From 0b6a2f9b29a288b8e18721be5264a5a7c24047b3 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Wed, 17 Jul 2024 11:33:13 +0200 Subject: [PATCH 1/2] planner: Fix BatchPointGetPlan.HandleColOffset --- pkg/planner/core/find_best_task.go | 13 ++++++++++++- .../r/executor/partition/issues.result | 12 ++++++++++++ .../t/executor/partition/issues.test | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index f274c53a8ec8c..364729b865e52 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2694,7 +2694,18 @@ func (ds *DataSource) convertToBatchPointGet(prop *property.PhysicalProperty, ca batchPointGetPlan.Handles = append(batchPointGetPlan.Handles, kv.IntHandle(ran.LowVal[0].GetInt64())) } batchPointGetPlan.accessCols = ds.TblCols - batchPointGetPlan.HandleColOffset = ds.HandleCols.GetCol(0).Index + found := false + for i := range ds.Columns { + if ds.Columns[i].ID == ds.HandleCols.GetCol(0).ID { + batchPointGetPlan.HandleColOffset = ds.Columns[i].Offset + found = true + break + } + } + if !found { + return base.InvalidTask + } + // Add filter condition to table plan now. if len(candidate.path.TableFilters) > 0 { batchPointGetPlan.Init(ds.SCtx(), ds.TableStats.ScaleByExpectCnt(accessCnt), ds.Schema().Clone(), ds.OutputNames(), ds.QueryBlockOffset()) diff --git a/tests/integrationtest/r/executor/partition/issues.result b/tests/integrationtest/r/executor/partition/issues.result index 429b6cd879775..31501ec43e373 100644 --- a/tests/integrationtest/r/executor/partition/issues.result +++ b/tests/integrationtest/r/executor/partition/issues.result @@ -433,3 +433,15 @@ select space(1), b from issue52198 where b in (1); space(1) b 1 drop table issue52198; +drop table if exists t; +set tidb_partition_prune_mode=static; +CREATE TABLE t ( +a text COLLATE utf8mb4_unicode_ci DEFAULT NULL, +b mediumint(8) unsigned NOT NULL DEFAULT '11075363', +c tinyblob NOT NULL, +PRIMARY KEY (b) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +PARTITION BY KEY (b) PARTITIONS 7; +insert into t values ('a' ,6970066, 'a'); +update t set c = 'AH6' where b in ( 7691699 ,11807884 ,10523838 ,15662349 ,6970066 ); +drop table t; diff --git a/tests/integrationtest/t/executor/partition/issues.test b/tests/integrationtest/t/executor/partition/issues.test index ad9e233a5bb03..be6d8c0139dbd 100644 --- a/tests/integrationtest/t/executor/partition/issues.test +++ b/tests/integrationtest/t/executor/partition/issues.test @@ -342,3 +342,17 @@ create table issue52198 (a int, b int, primary key (b)) partition by hash(b) par insert into issue52198 values (1,1); select space(1), b from issue52198 where b in (1); drop table issue52198; + +# TestIssues54667 +drop table if exists t; +set tidb_partition_prune_mode=static; +CREATE TABLE t ( + a text COLLATE utf8mb4_unicode_ci DEFAULT NULL, + b mediumint(8) unsigned NOT NULL DEFAULT '11075363', + c tinyblob NOT NULL, + PRIMARY KEY (b) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci +PARTITION BY KEY (b) PARTITIONS 7; +insert into t values ('a' ,6970066, 'a'); +update t set c = 'AH6' where b in ( 7691699 ,11807884 ,10523838 ,15662349 ,6970066 ); +drop table t; From 37bbe08ed1804bafa8b534f0507d668e133c9ceb Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Wed, 17 Jul 2024 18:35:57 +0800 Subject: [PATCH 2/2] Apply suggestions from code review --- tests/integrationtest/r/executor/partition/issues.result | 1 + tests/integrationtest/t/executor/partition/issues.test | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/integrationtest/r/executor/partition/issues.result b/tests/integrationtest/r/executor/partition/issues.result index 31501ec43e373..4d6651b1bef48 100644 --- a/tests/integrationtest/r/executor/partition/issues.result +++ b/tests/integrationtest/r/executor/partition/issues.result @@ -445,3 +445,4 @@ PARTITION BY KEY (b) PARTITIONS 7; insert into t values ('a' ,6970066, 'a'); update t set c = 'AH6' where b in ( 7691699 ,11807884 ,10523838 ,15662349 ,6970066 ); drop table t; +set tidb_partition_prune_mode=default; diff --git a/tests/integrationtest/t/executor/partition/issues.test b/tests/integrationtest/t/executor/partition/issues.test index be6d8c0139dbd..bb38384b885b5 100644 --- a/tests/integrationtest/t/executor/partition/issues.test +++ b/tests/integrationtest/t/executor/partition/issues.test @@ -356,3 +356,4 @@ PARTITION BY KEY (b) PARTITIONS 7; insert into t values ('a' ,6970066, 'a'); update t set c = 'AH6' where b in ( 7691699 ,11807884 ,10523838 ,15662349 ,6970066 ); drop table t; +set tidb_partition_prune_mode=default;