From 8ba1fa452b1ccdbfb85879ea94b9254aabba2916 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 28 Mar 2024 22:17:19 +0800 Subject: [PATCH] planner: Fix issue 52198, HandleColOffset was wrong. (#52210) (#52213) close pingcap/tidb#52198 --- pkg/planner/core/find_best_task.go | 12 +++++++++--- .../r/executor/partition/issues.result | 6 ++++++ .../integrationtest/t/executor/partition/issues.test | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 62f179491a871..2800568d38bd3 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2574,11 +2574,17 @@ func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candida pointGetPlan.Handle = kv.IntHandle(candidate.path.Ranges[0].LowVal[0].GetInt64()) pointGetPlan.UnsignedHandle = mysql.HasUnsignedFlag(ds.handleCols.GetCol(0).RetType.GetFlag()) pointGetPlan.accessCols = ds.TblCols - hc, err := ds.handleCols.ResolveIndices(ds.schema) - if err != nil { + found := false + for i := range ds.Columns { + if ds.Columns[i].ID == ds.handleCols.GetCol(0).ID { + pointGetPlan.HandleColOffset = ds.Columns[i].Offset + found = true + break + } + } + if !found { return invalidTask } - pointGetPlan.HandleColOffset = hc.GetCol(0).Index // Add filter condition to table plan now. if len(candidate.path.TableFilters) > 0 { sel := PhysicalSelection{ diff --git a/tests/integrationtest/r/executor/partition/issues.result b/tests/integrationtest/r/executor/partition/issues.result index c6750ed300647..35a21174abc12 100644 --- a/tests/integrationtest/r/executor/partition/issues.result +++ b/tests/integrationtest/r/executor/partition/issues.result @@ -427,3 +427,9 @@ TableReader_7 1.00 root partition:p0,p6 data:Selection_6 select * from t where col_29 between -7 and -6; col_29 -6 +create table issue52198 (a int, b int, primary key (b)) partition by hash(b) partitions 5; +insert into issue52198 values (1,1); +select space(1), b from issue52198 where b in (1); +space(1) b + 1 +drop table issue52198; diff --git a/tests/integrationtest/t/executor/partition/issues.test b/tests/integrationtest/t/executor/partition/issues.test index 385c2adbbf3b4..bcfd2357ea17b 100644 --- a/tests/integrationtest/t/executor/partition/issues.test +++ b/tests/integrationtest/t/executor/partition/issues.test @@ -337,3 +337,8 @@ explain select * from t where col_29 between -7 and -6; --sorted_result select * from t where col_29 between -7 and -6; +# TestIssue52198 +create table issue52198 (a int, b int, primary key (b)) partition by hash(b) partitions 5; +insert into issue52198 values (1,1); +select space(1), b from issue52198 where b in (1); +drop table issue52198;