在线 DDL 操作失败通常是由于以下情况之一引起的:The failure of an online DDL operation is typically due to one of the following conditions:
ALGORITHM子句指定的算法与特定类型的 DDL 操作或存储引擎不兼容。AnALGORITHMclause specifies an algorithm that is not compatible with the particular type of DDL operation or storage engine.LOCK子句指定了低级别的锁定(SHARED或NONE),这与特定类型的 DDL 操作不兼容。ALOCKclause specifies a low degree of locking (SHAREDorNONE) that is not compatible with the particular type of DDL operation.在等待表的 独占锁 时发生超时,该锁可能在 DDL 操作的初始和最终阶段短暂需要。A timeout occurs while waiting for an exclusive lock on the table, which may be needed briefly during the initial and final phases of the DDL operation.
在 MySQL 在创建索引期间将临时排序文件写入磁盘时,如果
tmpdir或innodb_tmpdir文件系统磁盘空间不足,就会发生此情况。有关更多信息,请参阅第 17.12.3 节,“在线 DDL 空间要求”。Thetmpdirorinnodb_tmpdirfile system runs out of disk space, while MySQL writes temporary sort files on disk during index creation. For more information, see Section 17.12.3, “Online DDL Space Requirements”.操作耗时较长,并且并发 DML 大量修改表,以至于临时在线日志的大小超过
innodb_online_alter_log_max_size配置选项的值。此情况会导致DB_ONLINE_LOG_TOO_BIG错误。The operation takes a long time and concurrent DML modifies the table so much that the size of the temporary online log exceeds the value of theinnodb_online_alter_log_max_sizeconfiguration option. This condition causes aDB_ONLINE_LOG_TOO_BIGerror.并发 DML 对表进行了更改,这些更改在原始表定义下是允许的,但在新表定义下是不允许的。该操作仅在最后阶段失败,当 MySQL 尝试应用所有来自并发 DML 语句的更改时。例如,当正在创建唯一索引时,你可能会向列中插入重复值,或者在为该列创建主键索引时,你可能会向列中插入
NULL值。并发 DML 所做的更改优先,ALTER TABLE操作实际上被回滚。Concurrent DML makes changes to the table that are allowed with the original table definition, but not with the new one. The operation only fails at the very end, when MySQL tries to apply all the changes from concurrent DML statements. For example, you might insert duplicate values into a column while a unique index is being created, or you might insertNULLvalues into a column while creating a primary key index on that column. The changes made by the concurrent DML take precedence, and theALTER TABLEoperation is effectively rolled back.