From 8c6cece2da9287ddffccb459c4db27951c73e087 Mon Sep 17 00:00:00 2001 From: Ruihao Chen Date: Tue, 30 Jun 2026 11:49:35 +0800 Subject: [PATCH 1/3] mysql-compatibility: clarify multi schema change DDL limits --- mysql-compatibility.md | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-compatibility.md b/mysql-compatibility.md index f32687a87e005..8dad646d193ab 100644 --- a/mysql-compatibility.md +++ b/mysql-compatibility.md @@ -162,6 +162,7 @@ TiDB supports most of the built-in functions in MySQL, but not all. You can use In TiDB, all supported DDL changes can be performed online. However, there are some major restrictions on DDL operations in TiDB compared to MySQL: * When using a single `ALTER TABLE` statement to alter multiple schema objects (such as columns or indexes) of a table, specifying the same object in multiple changes is not supported. For example, if you execute the `ALTER TABLE t1 MODIFY COLUMN c1 INT, DROP COLUMN c1` command, the `Unsupported operate same column/index` error is output. +* When using a single `ALTER TABLE` statement to alter multiple schema objects, TiDB validates dependencies in statement order, while MySQL might allow some statements based on the final table definition. For example, MySQL supports `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT` and `ALTER TABLE t ADD INDEX idx(...), DROP INDEX idx` with `idx` already existing. * It is not supported to modify multiple TiDB-specific schema objects using a single `ALTER TABLE` statement, such as `TIFLASH REPLICA`, `SHARD_ROW_ID_BITS`, and `AUTO_ID_CACHE`. * TiDB does not support the changes of some data types using `ALTER TABLE`. For example, TiDB does not support the change from the `DECIMAL` type to the `DATE` type. If a data type change is unsupported, TiDB reports the `Unsupported modify column: type %d not match origin %d` error. Refer to [`ALTER TABLE`](/sql-statements/sql-statement-modify-column.md) for more details. * The `ALGORITHM={INSTANT,INPLACE,COPY}` syntax functions only as an assertion in TiDB, and does not modify the `ALTER` algorithm. See [`ALTER TABLE`](/sql-statements/sql-statement-alter-table.md) for further details. From 799db7ea7766a91b041069ed14d16b6a446e7003 Mon Sep 17 00:00:00 2001 From: Ruihao Chen Date: Thu, 2 Jul 2026 10:36:20 +0800 Subject: [PATCH 2/3] mysql-compatibility: clarify multi schema change DDL limits --- mysql-compatibility.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-compatibility.md b/mysql-compatibility.md index 8dad646d193ab..fd327d8399d4c 100644 --- a/mysql-compatibility.md +++ b/mysql-compatibility.md @@ -162,7 +162,8 @@ TiDB supports most of the built-in functions in MySQL, but not all. You can use In TiDB, all supported DDL changes can be performed online. However, there are some major restrictions on DDL operations in TiDB compared to MySQL: * When using a single `ALTER TABLE` statement to alter multiple schema objects (such as columns or indexes) of a table, specifying the same object in multiple changes is not supported. For example, if you execute the `ALTER TABLE t1 MODIFY COLUMN c1 INT, DROP COLUMN c1` command, the `Unsupported operate same column/index` error is output. -* When using a single `ALTER TABLE` statement to alter multiple schema objects, TiDB validates dependencies in statement order, while MySQL might allow some statements based on the final table definition. For example, MySQL supports `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT` and `ALTER TABLE t ADD INDEX idx(...), DROP INDEX idx` with `idx` already existing. +* When using a single `ALTER TABLE` statement to alter multiple schema objects, TiDB does not resolve dependencies using schema objects added in the same statement. For example, MySQL supports `ALTER TABLE t ADD COLUMN c INT, ADD INDEX idx(c)` and `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT`, but TiDB reports `column does not exist: c`. +* TiDB does not support replacing an existing index by adding and dropping the same index name in one `ALTER TABLE` statement. For example, MySQL supports `ALTER TABLE t ADD INDEX idx(c), DROP INDEX idx` when `idx` already exists, but TiDB reports a duplicate-index error. * It is not supported to modify multiple TiDB-specific schema objects using a single `ALTER TABLE` statement, such as `TIFLASH REPLICA`, `SHARD_ROW_ID_BITS`, and `AUTO_ID_CACHE`. * TiDB does not support the changes of some data types using `ALTER TABLE`. For example, TiDB does not support the change from the `DECIMAL` type to the `DATE` type. If a data type change is unsupported, TiDB reports the `Unsupported modify column: type %d not match origin %d` error. Refer to [`ALTER TABLE`](/sql-statements/sql-statement-modify-column.md) for more details. * The `ALGORITHM={INSTANT,INPLACE,COPY}` syntax functions only as an assertion in TiDB, and does not modify the `ALTER` algorithm. See [`ALTER TABLE`](/sql-statements/sql-statement-alter-table.md) for further details. From 2b844ff8cfb27c2522d5ce5cbc65e43b3462384a Mon Sep 17 00:00:00 2001 From: Ruihao Chen Date: Fri, 3 Jul 2026 10:13:32 +0800 Subject: [PATCH 3/3] dm: document split multi schema change DDL behavior --- dm/dm-ddl-compatible.md | 12 ++++++++++++ mysql-compatibility.md | 2 -- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dm/dm-ddl-compatible.md b/dm/dm-ddl-compatible.md index 6262de342df81..936cce6029215 100644 --- a/dm/dm-ddl-compatible.md +++ b/dm/dm-ddl-compatible.md @@ -134,6 +134,18 @@ The following statements are rewritten before being replicated to the downstream |`^DROP TABLE...`|`^DROP TABLE...IF EXISTS`| |`^DROP INDEX...`|`^DROP INDEX...IF EXISTS`| +## Multi-schema-change DDL statements + +In some handling paths, such as replaying DDL statements recorded from gh-ost or pt-osc shadow tables during online DDL cut-over, DM might split a multi-schema-change `ALTER TABLE` statement into multiple standalone DDL statements. After the split, each generated DDL statement is applied independently to TiDB and to DM's schema tracker. Therefore, a statement that is accepted by the upstream as one atomic multi-change `ALTER TABLE` might fail after it is split if the generated DDL order is not independently executable. This does not necessarily mean that the original upstream DDL is invalid. + +For example, some MySQL-compatible upstreams support replacing an existing index with the same name in one statement: + +```sql +ALTER TABLE t ADD UNIQUE INDEX idx(c), DROP INDEX idx; +``` + +If DM splits or replays this statement as `ADD UNIQUE INDEX idx(c)` before `DROP INDEX idx`, the `ADD` statement fails because the old `idx` still exists. To avoid this issue, use DDL statements whose split execution order is valid on TiDB, such as dropping the old index and adding the new index as separate DDL statements in a safe order. If the migration task has already paused on such a DDL, use [`binlog replace`](/dm/handle-failed-ddl-statements.md) to replace it with equivalent TiDB-compatible DDL statements. + ## Shard merge migration tasks When DM merges and migrates tables in pessimistic or optimistic mode, the behavior of DDL replication is different from that in other scenarios. For details, refer to [Pessimistic Mode](/dm/feature-shard-merge-pessimistic.md) and [Optimistic Mode](/dm/feature-shard-merge-optimistic.md). diff --git a/mysql-compatibility.md b/mysql-compatibility.md index fd327d8399d4c..f32687a87e005 100644 --- a/mysql-compatibility.md +++ b/mysql-compatibility.md @@ -162,8 +162,6 @@ TiDB supports most of the built-in functions in MySQL, but not all. You can use In TiDB, all supported DDL changes can be performed online. However, there are some major restrictions on DDL operations in TiDB compared to MySQL: * When using a single `ALTER TABLE` statement to alter multiple schema objects (such as columns or indexes) of a table, specifying the same object in multiple changes is not supported. For example, if you execute the `ALTER TABLE t1 MODIFY COLUMN c1 INT, DROP COLUMN c1` command, the `Unsupported operate same column/index` error is output. -* When using a single `ALTER TABLE` statement to alter multiple schema objects, TiDB does not resolve dependencies using schema objects added in the same statement. For example, MySQL supports `ALTER TABLE t ADD COLUMN c INT, ADD INDEX idx(c)` and `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT`, but TiDB reports `column does not exist: c`. -* TiDB does not support replacing an existing index by adding and dropping the same index name in one `ALTER TABLE` statement. For example, MySQL supports `ALTER TABLE t ADD INDEX idx(c), DROP INDEX idx` when `idx` already exists, but TiDB reports a duplicate-index error. * It is not supported to modify multiple TiDB-specific schema objects using a single `ALTER TABLE` statement, such as `TIFLASH REPLICA`, `SHARD_ROW_ID_BITS`, and `AUTO_ID_CACHE`. * TiDB does not support the changes of some data types using `ALTER TABLE`. For example, TiDB does not support the change from the `DECIMAL` type to the `DATE` type. If a data type change is unsupported, TiDB reports the `Unsupported modify column: type %d not match origin %d` error. Refer to [`ALTER TABLE`](/sql-statements/sql-statement-modify-column.md) for more details. * The `ALGORITHM={INSTANT,INPLACE,COPY}` syntax functions only as an assertion in TiDB, and does not modify the `ALTER` algorithm. See [`ALTER TABLE`](/sql-statements/sql-statement-alter-table.md) for further details.