diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 836ba91108c8e..8093e2642d9c2 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2582,11 +2582,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 d564ce2855965..b0eda3a9e3aeb 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;