以下限制适用于在线 DDL 操作:The following limitations apply to online DDL operations:
在
TEMPORARY TABLE上创建索引时,表会被复制。The table is copied when creating an index on aTEMPORARY TABLE.如果表上存在
ON...CASCADE或ALTER TABLE约束,则不允许使用LOCK=NONE子句ON...SET NULL。TheALTER TABLEclauseLOCK=NONEis not permitted if there areON...CASCADEorON...SET NULLconstraints on the table.在原地在线 DDL 操作完成之前,它必须等待持有表的元数据锁的事务提交或回滚。在线 DDL 操作在执行阶段可能会短暂地需要对表加一个独占的元数据锁,并且在操作的最终阶段更新表定义时总是需要一个独占元数据锁。因此,持有表元数据锁的事务可能导致在线 DDL 操作被阻塞。持有表元数据锁的事务可能是在在线 DDL 操作之前或操作过程中开始的。持有表元数据锁的长期运行或不活跃的事务可能导致在线 DDL 操作超时。Before an in-place online DDL operation can finish, it must wait for transactions that hold metadata locks on the table to commit or roll back. An online DDL operation may briefly require an exclusive metadata lock on the table during its execution phase, and always requires one in the final phase of the operation when updating the table definition. Consequently, transactions holding metadata locks on the table can cause an online DDL operation to block. The transactions that hold metadata locks on the table may have been started before or during the online DDL operation. A long running or inactive transaction that holds a metadata lock on the table can cause an online DDL operation to timeout.
在执行就地在线 DDL 操作时,执行
ALTER TABLE语句的线程会应用来自其他连接线程在同一表上同时运行的 DML 操作的在线日志。当 DML 操作被应用时,即使重复的条目只是暂时的并且稍后会被在线日志中的其他条目恢复,也可能会遇到重复键条目错误(ERROR 1062 (23000): Duplicate entry)。这类似于InnoDB中的外键约束检查的概念,即约束必须在事务期间成立。When running an in-place online DDL operation, the thread that runs theALTER TABLEstatement applies an online log of DML operations that were run concurrently on the same table from other connection threads. When the DML operations are applied, it is possible to encounter a duplicate key entry error (ERROR 1062 (23000): Duplicate entry), even if the duplicate entry is only temporary and would be reverted by a later entry in the online log. This is similar to the idea of a foreign key constraint check inInnoDBin which constraints must hold during a transaction.OPTIMIZE TABLE对InnoDB表的操作映射为ALTER TABLE操作,用于重建表、更新索引统计信息并释放聚簇索引中未使用的空间。二级索引的创建效率不高,因为键是按出现在主键中的顺序插入的。OPTIMIZE TABLE支持通过在线 DDL 来重建常规和分区的InnoDB表。OPTIMIZE TABLEfor anInnoDBtable is mapped to anALTER TABLEoperation to rebuild the table and update index statistics and free unused space in the clustered index. Secondary indexes are not created as efficiently because keys are inserted in the order they appeared in the primary key.OPTIMIZE TABLEis supported with the addition of online DDL support for rebuilding regular and partitionedInnoDBtables.在 MySQL 5.6 之前创建的包含时间列(
DATE、DATETIME或TIMESTAMP)且未使用ALGORITHM=COPY重建的表,不支持ALGORITHM=INPLACE。在这种情况下,ALTER TABLE ... ALGORITHM=INPLACE操作将返回以下错误:Tables created before MySQL 5.6 that include temporal columns (DATE,DATETIMEorTIMESTAMP) and have not been rebuilt usingALGORITHM=COPYdo not supportALGORITHM=INPLACE. In this case, anALTER TABLE ... ALGORITHM=INPLACEoperation returns the following error:ERROR 1846 (0A000): ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.
以下限制通常适用于涉及重建表的大型表上的在线 DDL 操作:The following limitations are generally applicable to online DDL operations on large tables that involve rebuilding the table:
没有机制可以暂停在线 DDL 操作或限制在线 DDL 操作的 I/O 或 CPU 使用。There is no mechanism to pause an online DDL operation or to throttle I/O or CPU usage for an online DDL operation.
如果在线 DDL 操作失败,回滚可能会非常昂贵。Rollback of an online DDL operation can be expensive should the operation fail.
长时间运行的在线 DDL 操作可能会导致复制延迟。在线 DDL 操作必须在源端完成运行后才能在副本上运行。同时,在源端并发处理的 DML 仅在副本上的 DDL 操作完成后才会被处理。Long running online DDL operations can cause replication lag. An online DDL operation must finish running on the source before it is run on the replica. Also, DML that was processed concurrently on the source is only processed on the replica after the DDL operation on the replica is completed.
有关在大表上运行在线 DDL 操作的更多信息,请参见 第 17.12.2 节,“在线 DDL 性能与并发”。For additional information related to running online DDL operations on large tables, see Section 17.12.2, “Online DDL Performance and Concurrency”.