Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: fix a panic when creating key partition table (#16260) #17242

Merged
merged 3 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,9 @@ func (s *testIntegrationSuite3) TestCreateTableWithKeyPartition(c *C) {
s1 char(32) primary key
)
partition by key(s1) partitions 10;`)

tk.MustExec(`drop table if exists tm2`)
tk.MustExec(`create table tm2 (a char(5), unique key(a(5))) partition by key() partitions 5;`)
}

func (s *testIntegrationSuite5) TestAlterTableAddPartition(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ func checkTableInfoValidWithStmt(ctx sessionctx.Context, tbInfo *model.TableInfo
}
}

if err = checkRangePartitioningKeysConstraints(ctx, s, tbInfo); err != nil {
if err = checkPartitioningKeysConstraints(ctx, s, tbInfo); err != nil {
return errors.Trace(err)
}
}
Expand Down
7 changes: 5 additions & 2 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ func getPartitionIDs(table *model.TableInfo) []int64 {
return physicalTableIDs
}

// checkRangePartitioningKeysConstraints checks that the range partitioning key is included in the table constraint.
func checkRangePartitioningKeysConstraints(sctx sessionctx.Context, s *ast.CreateTableStmt, tblInfo *model.TableInfo) error {
// checkPartitioningKeysConstraints checks that the range partitioning key is included in the table constraint.
func checkPartitioningKeysConstraints(sctx sessionctx.Context, s *ast.CreateTableStmt, tblInfo *model.TableInfo) error {
// Returns directly if there are no unique keys in the table.
if len(tblInfo.Indices) == 0 && !tblInfo.PKIsHandle {
return nil
Expand All @@ -736,6 +736,9 @@ func checkRangePartitioningKeysConstraints(sctx sessionctx.Context, s *ast.Creat
partCols = columnInfoSlice(partColumns)
} else if len(s.Partition.ColumnNames) > 0 {
partCols = columnNameSlice(s.Partition.ColumnNames)
} else {
// TODO: Check keys constraints for list, key partition type and so on.
return nil
}

// Checks that the partitioning key is included in the constraint.
Expand Down