Skip to content

Commit 8d9e67b

Browse files
authored
planner: Fix issue 52198, HandleColOffset was wrong. (#52210)
close #52198
1 parent 927f3c6 commit 8d9e67b

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

pkg/planner/core/find_best_task.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,11 +2582,17 @@ func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candida
25822582
pointGetPlan.Handle = kv.IntHandle(candidate.path.Ranges[0].LowVal[0].GetInt64())
25832583
pointGetPlan.UnsignedHandle = mysql.HasUnsignedFlag(ds.handleCols.GetCol(0).RetType.GetFlag())
25842584
pointGetPlan.accessCols = ds.TblCols
2585-
hc, err := ds.handleCols.ResolveIndices(ds.schema)
2586-
if err != nil {
2585+
found := false
2586+
for i := range ds.Columns {
2587+
if ds.Columns[i].ID == ds.handleCols.GetCol(0).ID {
2588+
pointGetPlan.HandleColOffset = ds.Columns[i].Offset
2589+
found = true
2590+
break
2591+
}
2592+
}
2593+
if !found {
25872594
return invalidTask
25882595
}
2589-
pointGetPlan.HandleColOffset = hc.GetCol(0).Index
25902596
// Add filter condition to table plan now.
25912597
if len(candidate.path.TableFilters) > 0 {
25922598
sel := PhysicalSelection{

tests/integrationtest/r/executor/partition/issues.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,9 @@ TableReader_7 1.00 root partition:p0,p6 data:Selection_6
427427
select * from t where col_29 between -7 and -6;
428428
col_29
429429
-6
430+
create table issue52198 (a int, b int, primary key (b)) partition by hash(b) partitions 5;
431+
insert into issue52198 values (1,1);
432+
select space(1), b from issue52198 where b in (1);
433+
space(1) b
434+
1
435+
drop table issue52198;

tests/integrationtest/t/executor/partition/issues.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,8 @@ explain select * from t where col_29 between -7 and -6;
337337
--sorted_result
338338
select * from t where col_29 between -7 and -6;
339339

340+
# TestIssue52198
341+
create table issue52198 (a int, b int, primary key (b)) partition by hash(b) partitions 5;
342+
insert into issue52198 values (1,1);
343+
select space(1), b from issue52198 where b in (1);
344+
drop table issue52198;

0 commit comments

Comments
 (0)