Skip to content

Commit

Permalink
ddl: fix a panic when creating key partition table (#16260) (#17242)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored May 20, 2020
1 parent eabc946 commit ff187d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
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

0 comments on commit ff187d2

Please sign in to comment.