Before the introduction of online DDL, it was common practice to combine many DDL operations into
a single alter table statement. Because each alter table statement involved copying and
rebuilding the table, it was morę efficient to make several changes to the same table at once, sińce
those changes could all be done with a single rebuild operation for the table. The downside was that
SQL codę involving DDL operations was harder to maintain and to reuse in different Scripts. If the
specific changes were different each time, you might have to construct a
new complex alter table
for each slightly different scenario.
For DDL operations that can be done in-place, as shown in Table 5.9, “Summary of Online Status for
DDL Operations", now you can separate them into individual ALTER TABLE statements for easier
scripting and maintenance, without sacrificing efficiency. For example, you might take a complicated statement such as:
alter table tl add index il(cl), add unique index 12(c2), change c4_old_name c4_new_name integer unsigned;
and break it down into simpler parts that can be tested and performed independently, such as:
alter table tl add index 11(cl); alter table tl add unique index i2(c2);
alter table tl change c4_old_name c4_new_name integer unsigned not nuli;
You might still use multi-part alter table statements for:
• Operations that must be performed in a specific sequence, such as creating an index followed by a
foreign key constraint that uses that index.
• Operations all using the same specific lock clause, that you want to either succeed or fail as a
group.
• Operations that cannot be performed in-place, that is, that still copy and rebuild the table.
• Operations for which you specify algorithm=copy or old_alter_table=l, to force the tablecopying
behavior if needed for precise backward-compatibility in specialized scenarios.