diff --git a/ddl/column_change_test.go b/ddl/column_change_test.go index 4528564d2f231..62623e1aca3c4 100644 --- a/ddl/column_change_test.go +++ b/ddl/column_change_test.go @@ -437,3 +437,27 @@ func testNewContext(store kv.Storage) sessionctx.Context { ctx.Store = store return ctx } + +func TestIssue40135(t *testing.T) { + store, dom := testkit.CreateMockStoreAndDomain(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + + tk1 := testkit.NewTestKit(t, store) + tk1.MustExec("use test") + + tk.MustExec("CREATE TABLE t40135 ( a tinyint DEFAULT NULL, b varchar(32) DEFAULT 'md') PARTITION BY HASH (a) PARTITIONS 2") + one := true + hook := &ddl.TestDDLCallback{Do: dom} + var checkErr error + hook.OnJobRunBeforeExported = func(job *model.Job) { + if one { + one = false + _, checkErr = tk1.Exec("alter table t40135 change column a aNew SMALLINT NULL DEFAULT '-14996'") + } + } + 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") +} diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 2850a3aa968a5..2e2e1016507f9 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -4698,9 +4698,15 @@ func GetModifiableColumnJob( for _, name := range pt.GetPartitionColumnNames() { if strings.EqualFold(name.L, col.Name.L) { isPartitioningColumn = true + break } } if isPartitioningColumn { + // 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)) + } if !isColTypeAllowedAsPartitioningCol(newCol.FieldType) { return nil, dbterror.ErrNotAllowedTypeInPartition.GenWithStackByArgs(newCol.Name.O) } @@ -4744,7 +4750,6 @@ func GetModifiableColumnJob( newTblInfo.Columns = newCols var buf bytes.Buffer - // TODO: update the partitioning columns with new names if column is renamed AppendPartitionInfo(tblInfo.GetPartitionInfo(), &buf, mysql.ModeNone) // The parser supports ALTER TABLE ... PARTITION BY ... even if the ddl code does not yet :) // Ignoring warnings