mysql-compatibility: clarify multi schema change DDL limits#23170
mysql-compatibility: clarify multi schema change DDL limits#23170joechenrh wants to merge 1 commit into
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Code Review
This pull request updates mysql-compatibility.md to document two additional restrictions on multi-schema ALTER TABLE DDL operations in TiDB compared to MySQL: dependency validation order and modifying the same index multiple times in a single statement. The review feedback suggests minor phrasing adjustments to adhere to the style guide, specifically using the second person ("you"), avoiding passive voice, and correcting a minor grammatical article omission.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| 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 the dependencies in the statement order. MySQL might allow some multi-schema-change statements based on the final table definition. For example, MySQL supports `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT`, but TiDB returns an error because column `c` does not exist when the `ADD INDEX` clause is processed. Rewrite it as `ALTER TABLE t ADD COLUMN c INT, ADD INDEX idx_c(c)`. |
There was a problem hiding this comment.
To adhere to the style guide, we should write in the second person ("you") and avoid passive voice ("is processed").
| * When using a single `ALTER TABLE` statement to alter multiple schema objects, TiDB validates the dependencies in the statement order. MySQL might allow some multi-schema-change statements based on the final table definition. For example, MySQL supports `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT`, but TiDB returns an error because column `c` does not exist when the `ADD INDEX` clause is processed. Rewrite it as `ALTER TABLE t ADD COLUMN c INT, ADD INDEX idx_c(c)`. | |
| * When you use a single `ALTER TABLE` statement to alter multiple schema objects, TiDB validates the dependencies in the statement order. MySQL might allow some multi-schema-change statements based on the final table definition. For example, MySQL supports `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT`, but TiDB returns an error because column `c` does not exist when TiDB processes the `ADD INDEX` clause. You can rewrite the statement as `ALTER TABLE t ADD COLUMN c INT, ADD INDEX idx_c(c)`. |
|
|
||
| * 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 the dependencies in the statement order. MySQL might allow some multi-schema-change statements based on the final table definition. For example, MySQL supports `ALTER TABLE t ADD INDEX idx_c(c), ADD COLUMN c INT`, but TiDB returns an error because column `c` does not exist when the `ADD INDEX` clause is processed. Rewrite it as `ALTER TABLE t ADD COLUMN c INT, ADD INDEX idx_c(c)`. | ||
| * If table `t` already has an index named `idx`, MySQL can treat `ADD INDEX idx(...), DROP INDEX idx` in a single `ALTER TABLE` statement as replacing the existing index. TiDB does not support modifying the same index multiple times in a single `ALTER TABLE` statement. Rewrite it as separate statements, such as `ALTER TABLE t DROP INDEX idx` followed by `ALTER TABLE t ADD INDEX idx(...)`. |
There was a problem hiding this comment.
To adhere to the style guide, we should write in the second person ("you") and improve the grammar ("If table t" -> "If a table t").
| * If table `t` already has an index named `idx`, MySQL can treat `ADD INDEX idx(...), DROP INDEX idx` in a single `ALTER TABLE` statement as replacing the existing index. TiDB does not support modifying the same index multiple times in a single `ALTER TABLE` statement. Rewrite it as separate statements, such as `ALTER TABLE t DROP INDEX idx` followed by `ALTER TABLE t ADD INDEX idx(...)`. | |
| * If a table `t` already has an index named `idx`, MySQL can treat `ADD INDEX idx(...), DROP INDEX idx` in a single `ALTER TABLE` statement as replacing the existing index. TiDB does not support modifying the same index multiple times in a single `ALTER TABLE` statement. You can rewrite the statement as separate statements, such as `ALTER TABLE t DROP INDEX idx` followed by `ALTER TABLE t ADD INDEX idx(...)`. |
References
- Write in second person ("you") when addressing users. (link)
604ad33 to
5d346dc
Compare
5d346dc to
8c6cece
Compare
What is changed, added or deleted? (Required)
Clarify TiDB DDL compatibility limits for multi-schema-change
ALTER TABLEstatements:ADD INDEX idx_c(c), ADD COLUMN c INTandADD INDEX idx(...), DROP INDEX idxwithidxalready existing.Which TiDB version(s) do your changes apply to? (Required)
What is the related PR or file link(s)?
Do your changes match any of the following descriptions?