10.5.7 Optimizing InnoDB DDL Operations
MySQL 8.4 Reference Manual Including MySQL NDB Cluster 8.4
10.5.7 Optimizing InnoDB DDL Operations
- Many DDL operations on tables and indexes
(
CREATE,ALTER, andDROPstatements) can be performed online. See Section 17.12, “InnoDB and Online DDL” for details. - Online DDL support for adding secondary indexes means that you can generally speed up the process of creating and loading a table and associated indexes by creating the table without secondary indexes, then adding secondary indexes after the data is loaded.
- Use
TRUNCATE TABLEto empty a table, notDELETE FROM tbl_name. Foreign key constraints can make aTRUNCATEstatement work like a regularDELETEstatement, in which case a sequence of commands likeDROP TABLEandCREATE TABLEmight be fastest. - Because the primary key is integral to the storage layout of
each
InnoDBtable, and changing the definition of the primary key involves reorganizing the whole table, always set up the primary key as part of theCREATE TABLEstatement, and plan ahead so that you do not need toALTERorDROPthe primary key afterward.
