diff --git a/ddl/db_partition_test.go b/ddl/db_partition_test.go index fbf8a3782378f..fb1fc104f4ff8 100644 --- a/ddl/db_partition_test.go +++ b/ddl/db_partition_test.go @@ -4685,7 +4685,7 @@ func TestAlterModifyColumnOnPartitionedTableFail(t *testing.T) { tk.MustGetErrCode(`alter table t modify a varchar(5)`, errno.WarnDataTruncated) tk.MustExec(`SET SQL_MODE = ''`) tk.MustExec(`alter table t modify a varchar(5)`) - // TODO: Investigate why there are no warnings here?!? + // fix https://github.com/pingcap/tidb/issues/38669 and update this tk.MustQuery(`show warnings`).Check(testkit.Rows()) tk.MustExec(`SET SQL_MODE = DEFAULT`) tk.MustQuery(`select * from t`).Sort().Check(testkit.Rows(""+ @@ -4731,4 +4731,13 @@ func TestAlterModifyColumnOnPartitionedTableFail(t *testing.T) { // OK to decrease, since with RANGE COLUMNS, it will check the partition definition values against the new type tk.MustExec(`alter table t modify a smallint`) tk.MustExec(`alter table t modify a bigint`) + + tk.MustExec(`drop table t`) + + tk.MustExec(`create table t (a int, b varchar(255), key (b)) partition by list columns (b) (partition p1 values in ("1", "ab", "12345"), partition p2 values in ("2", "abc", "999999"))`) + tk.MustExec(`insert into t values (1, "1"), (2, "2"), (999999, "999999")`) + tk.MustContainErrMsg(`alter table t modify column b varchar(5)`, "[ddl:8200]New column does not match partition definitions: [ddl:1654]Partition column values of incorrect type") + tk.MustExec(`set sql_mode = ''`) + tk.MustContainErrMsg(`alter table t modify column b varchar(5)`, "[ddl:8200]New column does not match partition definitions: [ddl:1654]Partition column values of incorrect type") + tk.MustExec(`set sql_mode = default`) } diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index e9a502877c384..4e8642289abbd 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -4649,7 +4649,12 @@ func GetModifiableColumnJob( return nil, dbterror.ErrUnsupportedModifyColumn.GenWithStack("cannot parse generated PartitionInfo") } pAst := at.Specs[0].Partition - if _, err = buildPartitionDefinitionsInfo(sctx, pAst.Definitions, &newTblInfo); err != nil { + sv := sctx.GetSessionVars().StmtCtx + oldTruncAsWarn, oldIgnoreTrunc := sv.TruncateAsWarning, sv.IgnoreTruncate + sv.TruncateAsWarning, sv.IgnoreTruncate = false, false + _, err = buildPartitionDefinitionsInfo(sctx, pAst.Definitions, &newTblInfo) + sv.TruncateAsWarning, sv.IgnoreTruncate = oldTruncAsWarn, oldIgnoreTrunc + if err != nil { return nil, dbterror.ErrUnsupportedModifyColumn.GenWithStack("New column does not match partition definitions: %s", err.Error()) } }