From 333071107ccb2f80bd9384cf8627f19cf9b2b4eb Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Mon, 22 Jul 2024 10:22:34 +0200 Subject: [PATCH 1/2] This is an automated cherry-pick of #54686 Signed-off-by: ti-chi-bot --- pkg/planner/core/find_best_task.go | 15 +++++++++++++++ .../r/executor/partition/issues.result | 13 +++++++++++++ .../t/executor/partition/issues.test | 15 +++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 3ba8e26113556..aa30f6b296dc3 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2661,7 +2661,22 @@ func (ds *DataSource) convertToBatchPointGet(prop *property.PhysicalProperty, ca batchPointGetPlan.Handles = append(batchPointGetPlan.Handles, kv.IntHandle(ran.LowVal[0].GetInt64())) } batchPointGetPlan.accessCols = ds.TblCols +<<<<<<< HEAD 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 + } + +>>>>>>> 669bf4d4800 (planner: Fix BatchPointGetPlan.HandleColOffset (#54686)) // 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.names, ds.QueryBlockOffset()) diff --git a/tests/integrationtest/r/executor/partition/issues.result b/tests/integrationtest/r/executor/partition/issues.result index b0eda3a9e3aeb..2893b92b0d89b 100644 --- a/tests/integrationtest/r/executor/partition/issues.result +++ b/tests/integrationtest/r/executor/partition/issues.result @@ -433,3 +433,16 @@ 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; +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 bcfd2357ea17b..b68f28979103a 100644 --- a/tests/integrationtest/t/executor/partition/issues.test +++ b/tests/integrationtest/t/executor/partition/issues.test @@ -342,3 +342,18 @@ 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; +set tidb_partition_prune_mode=default; From 35e21811b5ae232953a84eebddc616c81a772528 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Mon, 5 Aug 2024 11:38:45 +0200 Subject: [PATCH 2/2] Manual merge resolved --- pkg/planner/core/find_best_task.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index aa30f6b296dc3..185898361e811 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2661,22 +2661,18 @@ func (ds *DataSource) convertToBatchPointGet(prop *property.PhysicalProperty, ca batchPointGetPlan.Handles = append(batchPointGetPlan.Handles, kv.IntHandle(ran.LowVal[0].GetInt64())) } batchPointGetPlan.accessCols = ds.TblCols -<<<<<<< HEAD - batchPointGetPlan.HandleColOffset = ds.handleCols.GetCol(0).Index -======= found := false for i := range ds.Columns { - if ds.Columns[i].ID == ds.HandleCols.GetCol(0).ID { + if ds.Columns[i].ID == ds.handleCols.GetCol(0).ID { batchPointGetPlan.HandleColOffset = ds.Columns[i].Offset found = true break } } if !found { - return base.InvalidTask + return invalidTask } ->>>>>>> 669bf4d4800 (planner: Fix BatchPointGetPlan.HandleColOffset (#54686)) // 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.names, ds.QueryBlockOffset())