Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 31.0Mb
PDF (A4) - 31.0Mb
PDF (RPM) - 29.2Mb
HTML Download (TGZ) - 7.2Mb
HTML Download (Zip) - 7.2Mb
HTML Download (RPM) - 6.2Mb
Man Pages (TGZ) - 175.7Kb
Man Pages (Zip) - 285.9Kb
Info (Gzip) - 3.0Mb
Info (Zip) - 3.0Mb
Excerpts from this Manual

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

14.13 InnoDB and Online DDL

The online DDL feature permits in-place table alterations or concurrent DML, or both. 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.

  • The ability to adjust the balance between performance and concurrency during DDL operations using the LOCK clause. See The LOCK clause.

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

The online DDL feature builds on the InnoDB Fast Index Creation feature that is available in MySQL 5.5, which optimized CREATE INDEX and DROP INDEX to avoid table-copying behavior.

The NDB Cluster NDB storage engine also supports online table schema changes, but uses its own syntax that is not compatible with the syntax used for InnoDB online DDL operations. For more information, see Section 13.1.7.2, “ALTER TABLE Online Operations in NDB Cluster”.

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

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

ALTER TABLE tbl_name ADD PRIMARY KEY (column), ALGORITHM=INPLACE, LOCK=NONE;

The LOCK clause is useful for fine-tuning the degree of concurrent access to the table. The ALGORITHM 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, specify a clause on the ALTER TABLE statement such as LOCK=NONE (permit reads and writes) or LOCK=SHARED (permit reads). The operation halts immediately if the requested level of concurrency is not available.

  • To compare performance, run a statement with ALGORITHM=INPLACE and ALGORITHM=COPY. Alternatively, run a statement with the old_alter_table configuration option disabled and enabled.

  • To avoid tying up the server with an ALTER TABLE operation that copies the table, include ALGORITHM=INPLACE. The statement halts immediately if it cannot use the in-place mechanism.


User Comments
Sign Up Login You must be logged in to post a comment.