Skip to content

Commit

Permalink
ddl: LINEAR HASH as HASH partitioned table (#38451)
Browse files Browse the repository at this point in the history
close #38450
  • Loading branch information
mjonss authored Oct 19, 2022
1 parent 51e559c commit 298ce91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 8 additions & 1 deletion ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,14 @@ func TestCreateTableWithHashPartition(t *testing.T) {
) PARTITION BY HASH(store_id) PARTITIONS 102400000000;`, errno.ErrTooManyPartitions)

tk.MustExec("CREATE TABLE t_linear (a int, b varchar(128)) PARTITION BY LINEAR HASH(a) PARTITIONS 4")
tk.MustGetErrCode("select * from t_linear partition (p0)", errno.ErrPartitionClauseOnNonpartitioned)
tk.MustQuery(`show warnings`).Check(testkit.Rows("Warning 8200 LINEAR HASH is not supported, using non-linear HASH instead"))
tk.MustQuery(`show create table t_linear`).Check(testkit.Rows("" +
"t_linear CREATE TABLE `t_linear` (\n" +
" `a` int(11) DEFAULT NULL,\n" +
" `b` varchar(128) DEFAULT NULL\n" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" +
"PARTITION BY HASH (`a`) PARTITIONS 4"))
tk.MustQuery("select * from t_linear partition (p0)").Check(testkit.Rows())

tk.MustExec(`CREATE TABLE t_sub (a int, b varchar(128)) PARTITION BY RANGE( a ) SUBPARTITION BY HASH( a )
SUBPARTITIONS 2 (
Expand Down
7 changes: 5 additions & 2 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,11 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.PartitionOptions, tb
}
case model.PartitionTypeHash:
// Partition by hash is enabled by default.
// Note that linear hash is not enabled.
if !s.Linear && s.Sub == nil {
// Note that linear hash is simply ignored, and creates non-linear hash.
if s.Linear {
ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ErrUnsupportedCreatePartition.GenWithStack("LINEAR HASH is not supported, using non-linear HASH instead"))
}
if s.Sub == nil {
enable = true
}
case model.PartitionTypeList:
Expand Down
2 changes: 1 addition & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ func (b *executorBuilder) setTelemetryInfo(v *plannercore.DDL) {
}
}
case model.PartitionTypeHash:
if !p.Linear && p.Sub == nil {
if p.Sub == nil {
b.Ti.PartitionTelemetry.UseTablePartitionHash = true
}
case model.PartitionTypeList:
Expand Down

0 comments on commit 298ce91

Please sign in to comment.