Skip to content

Commit

Permalink
planner: Fix issue 52198, HandleColOffset was wrong. (#52210)
Browse files Browse the repository at this point in the history
close #52198
  • Loading branch information
mjonss authored Mar 28, 2024
1 parent 927f3c6 commit 8d9e67b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
6 changes: 6 additions & 0 deletions tests/integrationtest/r/executor/partition/issues.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 5 additions & 0 deletions tests/integrationtest/t/executor/partition/issues.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 8d9e67b

Please sign in to comment.