Skip to content

Commit

Permalink
ddl: fix 'alter table drop partition' check on hash partitioned table (
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and bb7133 committed Jun 21, 2019
1 parent 5cd77cd commit 10e0086
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ func (s *testIntegrationSuite5) TestAlterTableDropPartition(c *C) {
tk.MustExec("alter table table4 drop partition PAR5;")
sql4 := "alter table table4 drop partition PAR0;"
assertErrorCode(c, tk, sql4, tmysql.ErrDropPartitionNonExistent)

tk.MustExec("CREATE TABLE t1 (a int(11), b varchar(64)) PARTITION BY HASH(a) PARTITIONS 3")
assertErrorCode(c, tk, "alter table t1 drop partition p2", tmysql.ErrOnlyOnRangeListPartition)
}

func (s *testIntegrationSuite4) TestAddPartitionTooManyPartitions(c *C) {
Expand Down
3 changes: 3 additions & 0 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var (
errInvalidSplitRegionRanges = terror.ClassDDL.New(codeInvalidRanges, "Failed to split region ranges")
errReorgPanic = terror.ClassDDL.New(codeReorgWorkerPanic, "reorg worker panic.")

errOnlyOnRangeListPartition = terror.ClassDDL.New(codeOnlyOnRangeListPartition, mysql.MySQLErrName[mysql.ErrOnlyOnRangeListPartition])
// errWrongKeyColumn is for table column cannot be indexed.
errWrongKeyColumn = terror.ClassDDL.New(codeWrongKeyColumn, mysql.MySQLErrName[mysql.ErrWrongKeyColumn])
// errUnsupportedOnGeneratedColumn is for unsupported actions on generated columns.
Expand Down Expand Up @@ -755,6 +756,7 @@ const (
codeSubpartition = terror.ErrCode(mysql.ErrSubpartition)
codeSystemVersioningWrongPartitions = terror.ErrCode(mysql.ErrSystemVersioningWrongPartitions)
codeWrongPartitionTypeExpectedSystemTime = terror.ErrCode(mysql.ErrWrongPartitionTypeExpectedSystemTime)
codeOnlyOnRangeListPartition = terror.ErrCode(mysql.ErrOnlyOnRangeListPartition)
)

func init() {
Expand Down Expand Up @@ -825,6 +827,7 @@ func init() {
codeSubpartition: mysql.ErrSubpartition,
codeSystemVersioningWrongPartitions: mysql.ErrSystemVersioningWrongPartitions,
codeWrongPartitionTypeExpectedSystemTime: mysql.ErrWrongPartitionTypeExpectedSystemTime,
codeOnlyOnRangeListPartition: mysql.ErrOnlyOnRangeListPartition,
}
terror.ErrClassToMySQLCodes[terror.ClassDDL] = ddlMySQLErrCodes
}
6 changes: 5 additions & 1 deletion ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ func validRangePartitionType(col *table.Column) bool {

// checkDropTablePartition checks if the partition exists and does not allow deleting the last existing partition in the table.
func checkDropTablePartition(meta *model.TableInfo, partName string) error {
oldDefs := meta.Partition.Definitions
pi := meta.Partition
if pi.Type != model.PartitionTypeRange && pi.Type != model.PartitionTypeList {
return errOnlyOnRangeListPartition.GenWithStackByArgs("DROP")
}
oldDefs := pi.Definitions
for _, def := range oldDefs {
if strings.EqualFold(def.Name.L, strings.ToLower(partName)) {
if len(oldDefs) == 1 {
Expand Down

0 comments on commit 10e0086

Please sign in to comment.