Documentation Home
MySQL 9.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 261.1Kb
Man Pages (Zip) - 368.3Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.3 Reference Manual  / The InnoDB Storage Engine  /  InnoDB and Online DDL

17.12 InnoDB and Online DDL

The online DDL feature provides support for instant and in-place table alterations and concurrent DML. Benefits of this feature include:

  • Improved responsiveness and availability in busy production environments, where making a table unavailable for minutes or hours is not practical.

  • For in-place operations, the ability to adjust the balance between performance and concurrency during DDL operations using theLOCK clause. SeeThe LOCK clause.

  • Less disk space usage and I/O overhead than the table-copy method.

Typically, you do not need to do anything special to enable online DDL. By default, MySQL performs the operation instantly or in place, as permitted, with as little locking as possible.

You can control aspects of a DDL operation using theALGORITHM andLOCK clauses of theALTER TABLE statement. These clauses are placed at the end of the statement, separated from the table and column specifications by commas. For example:

ALTER TABLEtbl_name ADD PRIMARY KEY (column), ALGORITHM=INPLACE;

TheLOCK clause may be used for operations that are performed in place and is useful for fine-tuning the degree of concurrent access to the table during operations. OnlyLOCK=DEFAULT is supported for operations that are performed instantly. TheALGORITHM clause is primarily intended for performance comparisons and as a fallback to the older table-copying behavior in case you encounter any issues. For example:

  • To avoid accidentally making the table unavailable for reads, writes, or both, during an in-placeALTER TABLE operation, specify a clause on theALTER TABLE statement such asLOCK=NONE (permit reads and writes) orLOCK=SHARED (permit reads). The operation halts immediately if the requested level of concurrency is not available.

  • To compare performance between algorithms, run a statement withALGORITHM=INSTANT,ALGORITHM=INPLACE andALGORITHM=COPY. You can also run a statement with theold_alter_table configuration option enabled to force the use ofALGORITHM=COPY.

  • To avoid tying up the server with anALTER TABLE operation that copies the table, includeALGORITHM=INSTANT orALGORITHM=INPLACE. The statement halts immediately if it cannot use the specified algorithm.