Skip to content

Commit

Permalink
planner,executor: fix select big number on hash partition table panic (
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Jun 12, 2020
1 parent 1dc57ed commit d445e55
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion executor/batch_point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,6 @@ func getPhysID(tblInfo *model.TableInfo, val kv.Handle) int64 {
if pi == nil {
return tblInfo.ID
}
partIdx := math.Abs(val.IntValue()) % int64(pi.Num) // TODO: fix me for table, partition on cluster index.
partIdx := math.Abs(val.IntValue() % int64(pi.Num)) // TODO: fix me for table, partition on cluster index.
return pi.Definitions[partIdx].ID
}
11 changes: 11 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ func (s *testIntegrationSuite) TestIssue15546(c *C) {
tk.MustQuery("select * from pt, vt where pt.a = vt.a").Check(testkit.Rows("1 1 1 1"))
}

func (s *testIntegrationSuite) TestIssue17813(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("use test")
tk.MustExec("drop table if exists hash_partition_overflow")
tk.MustExec("create table hash_partition_overflow (c0 bigint unsigned) partition by hash(c0) partitions 3")
tk.MustExec("insert into hash_partition_overflow values (9223372036854775808)")
tk.MustQuery("select * from hash_partition_overflow where c0 = 9223372036854775808").Check(testkit.Rows("9223372036854775808"))
tk.MustQuery("select * from hash_partition_overflow where c0 in (1, 9223372036854775808)").Check(testkit.Rows("9223372036854775808"))
}

func (s *testIntegrationSuite) TestHintWithRequiredProperty(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
2 changes: 1 addition & 1 deletion planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ func getPartitionInfo(ctx sessionctx.Context, tbl *model.TableInfo, pairs []name
for i, pair := range pairs {
if partitionColName.Name.L == pair.colName {
val := pair.value.GetInt64()
pos := math.Abs(val) % int64(pi.Num)
pos := math.Abs(val % int64(pi.Num))
return &pi.Definitions[pos], i
}
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (s *partitionProcessor) pruneHashPartition(ds *DataSource, pi *model.Partit
return tableDual, nil
}
if ok {
idx := math.Abs(val) % int64(pi.Num)
idx := math.Abs(val % int64(pi.Num))
if len(ds.partitionNames) > 0 && !s.findByName(ds.partitionNames, pi.Definitions[idx].Name.L) {
// For condition like `from t partition (p1) where a = 5`, but they are conflict, return TableDual directly.
tableDual := LogicalTableDual{RowCount: 0}.Init(ds.SCtx(), ds.blockOffset)
Expand Down
5 changes: 3 additions & 2 deletions table/tables/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,11 @@ func (t *partitionedTable) locateHashPartition(ctx sessionctx.Context, pi *model
if isNull {
return 0, nil
}
ret = ret % int64(t.meta.Partition.Num)
if ret < 0 {
ret = 0 - ret
ret = -ret
}
return int(ret % int64(t.meta.Partition.Num)), nil
return int(ret), nil
}

// GetPartition returns a Table, which is actually a partition.
Expand Down

0 comments on commit d445e55

Please sign in to comment.