diff --git a/ddl/column_change_test.go b/ddl/column_change_test.go index fa17f0cec7272..d12e4dd62db27 100644 --- a/ddl/column_change_test.go +++ b/ddl/column_change_test.go @@ -444,7 +444,7 @@ func TestIssue40150(t *testing.T) { tk.MustExec("use test") tk.MustExec("CREATE TABLE t40150 (a int) PARTITION BY HASH (a) PARTITIONS 2") - tk.MustContainErrMsg(`alter table t40150 rename column a to c`, "[ddl:8200]Unsupported RENAME COLUMN 'a' has a partitioning function dependency and cannot be renamed") + tk.MustContainErrMsg(`alter table t40150 rename column a to c`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") } func TestIssue40135(t *testing.T) { @@ -468,5 +468,5 @@ func TestIssue40135(t *testing.T) { dom.DDL().SetHook(hook) tk.MustExec("alter table t40135 modify column a MEDIUMINT NULL DEFAULT '6243108' FIRST") - require.ErrorContains(t, checkErr, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed") + require.ErrorContains(t, checkErr, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") } diff --git a/ddl/db_partition_test.go b/ddl/db_partition_test.go index ad96365c4668f..ab9890dbefc8d 100644 --- a/ddl/db_partition_test.go +++ b/ddl/db_partition_test.go @@ -4535,19 +4535,19 @@ func TestAlterModifyColumnOnPartitionedTableRename(t *testing.T) { tk.MustExec("create database " + schemaName) tk.MustExec("use " + schemaName) tk.MustExec(`create table t (a int, b char) partition by range (a) (partition p0 values less than (10))`) - tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed") + tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") tk.MustExec(`drop table t`) tk.MustExec(`create table t (a char, b char) partition by range columns (a) (partition p0 values less than ('z'))`) - tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed") + tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") tk.MustExec(`drop table t`) tk.MustExec(`create table t (a int, b char) partition by list (a) (partition p0 values in (10))`) - tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed") + tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") tk.MustExec(`drop table t`) tk.MustExec(`create table t (a char, b char) partition by list columns (a) (partition p0 values in ('z'))`) - tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed") + tk.MustContainErrMsg(`alter table t change a c char`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") tk.MustExec(`drop table t`) tk.MustExec(`create table t (a int, b char) partition by hash (a) partitions 3`) - tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:8200]Unsupported modify column: Column 'a' has a partitioning function dependency and cannot be renamed") + tk.MustContainErrMsg(`alter table t change a c int`, "[ddl:3885]Column 'a' has a partitioning function dependency and cannot be dropped or renamed") } func TestDropPartitionKeyColumn(t *testing.T) { diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 08041a3e59f45..2ae8a46134d4b 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -4734,7 +4734,7 @@ func GetModifiableColumnJob( // TODO: update the partitioning columns with new names if column is renamed // Would be an extension from MySQL which does not support it. if col.Name.L != newCol.Name.L { - return nil, dbterror.ErrUnsupportedModifyColumn.GenWithStackByArgs(fmt.Sprintf("Column '%s' has a partitioning function dependency and cannot be renamed", col.Name.O)) + return nil, dbterror.ErrDependentByPartitionFunctional.GenWithStackByArgs(col.Name.L) } if !isColTypeAllowedAsPartitioningCol(newCol.FieldType) { return nil, dbterror.ErrNotAllowedTypeInPartition.GenWithStackByArgs(newCol.Name.O) @@ -5110,18 +5110,9 @@ func (d *ddl) RenameColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.Al } } - if tbl.Meta().Partition != nil { - if pt, ok := tbl.(table.PartitionedTable); ok && pt != nil { - for _, name := range pt.GetPartitionColumnNames() { - if strings.EqualFold(name.L, oldColName.L) { - return dbterror.ErrGeneralUnsupportedDDL.GenWithStackByArgs( - fmt.Sprintf("RENAME COLUMN '%s' has a partitioning function dependency and cannot be renamed", oldColName.O)) - } - } - } else { - return dbterror.ErrGeneralUnsupportedDDL.GenWithStackByArgs( - "RENAME COLUMN due to partitioned table") - } + err = checkDropColumnWithPartitionConstraint(tbl, oldColName) + if err != nil { + return errors.Trace(err) } tzName, tzOffset := ddlutil.GetTimeZone(ctx)