Summary of Online Status for DDL Operations
Operation | In-Place? | Copies Table? | Allows Concurrent DML? | Allows Concurrent Query? | Notes |
---|---|---|---|---|---|
CREATE ,ADD |
Yes* | No* | Yes | Yes |
Some restrictions for FULLTEXT index; see next row. Currently,the operation is not in-place (that is, it copies the table) if the same index being created was also dropped by an earlier clause in the same ALTER statement. |
ADD |
Yes | No* | No | Yes |
Creating the first FULLTEXT index for a table involvesa table copy, unless there is a user-supplied FTS_DOC_ID column.Subsequent FULLTEXT indexes on the same table can be createdin-place. |
DROP |
Yes | No | Yes | Yes | |
OPTIMIZE |
Yes | Yes | Yes | Yes |
Uses ALGORITHM=INPLACE as of MySQL 5.6.17. ALGORITHM=COPY isused if old_alter_table=1 ormysqld --skip-new optionis enabled. OPTIMIZE TABLE using online DDL (ALGORITHM=INPLACE )is not supported for tables with FULLTEXT indexes. |
Set default value for a column | Yes | No | Yes | Yes |
Modifies .frm file only, not the data file. |
Change auto-increment value for a column |
Yes | No | Yes | Yes | Modifies a value stored in memory, not the data file. |
Add a foreign key constraint |
Yes* | No* | Yes | Yes |
To avoid copying the table, disableforeign_key_checks duringconstraint creation. |
Drop a foreign key constraint |
Yes | No | Yes | Yes |
The foreign_key_checks optioncan be enabled or disabled. |
Rename a column | Yes* | No* | Yes* | Yes | To allow concurrent DML, keep the same data type and only change the column name. |
Add a column | Yes | Yes | Yes* | Yes |
Concurrent DML is not allowed when adding an auto-increment column. Although ALGORITHM=INPLACE is allowed, the data is reorganizedsubstantially, so it is still an expensive operation. |
Drop a column | Yes | Yes | Yes | Yes |
Although ALGORITHM=INPLACE is allowed, the data is reorganizedsubstantially, so it is still an expensive operation. |
Reorder columns | Yes | Yes | Yes | Yes |
Although ALGORITHM=INPLACE is allowed, the data is reorganizedsubstantially, so it is still an expensive operation. |
ChangeROW_FORMAT property |
Yes | Yes | Yes | Yes |
Although ALGORITHM=INPLACE is allowed, the data is reorganizedsubstantially, so it is still an expensive operation. |
ChangeKEY_BLOCK_SIZE property |
Yes | Yes | Yes | Yes |
Although ALGORITHM=INPLACE is allowed, the data is reorganizedsubstantially, so it is still an expensive operation. |
Make columnNULL |
Yes | Yes | Yes | Yes |
Although ALGORITHM=INPLACE is allowed, the data is reorganizedsubstantially, so it is still an expensive operation. |
Make column NOT NULL |
Yes* | Yes | Yes | Yes |
When SQL_MODE includesstrict_all_tables orstrict_all_tables ,the operation fails if the column contains any nulls. Although ALGORITHM=INPLACE isallowed, the data is reorganized substantially, so it is still an expensive operation. |
Change data type of column | No | Yes | No | Yes | |
Add primary key |
Yes* | Yes | Yes | Yes |
Although ALGORITHM=INPLACE is allowed, the data is reorganizedsubstantially, so it is still an expensive operation. ALGORITHM=INPLACE isnot allowed under certain conditions if columns have to be converted to NOT . See Example 14.9,“Creating and Dropping the Primary Key”. |
Drop primary keyand add another |
Yes | Yes | Yes | Yes |
ALGORITHM=INPLACE is only allowed when you add a new primarykey in the same ALTER ; the data is reorganized substantially, so it is still an expensive operation. |
Drop primary key |
No | Yes | No | Yes |
Restrictions apply when you drop a primary key primary key without adding a new one in the same ALTER statement. |
Convert character set | No | Yes | No | Yes | Rebuilds the table if the new character encoding is different. |
Specify character set | No | Yes | No | Yes | Rebuilds the table if the new character encoding is different. |
Rebuild withFORCE option |
Yes | Yes | Yes | Yes |
Uses ALGORITHM=INPLACE as of MySQL 5.6.17. ALGORITHM=COPY isused if old_alter_table=1 ormysqld --skip-new optionis enabled. Table rebuild using online DDL ( ALGORITHM=INPLACE )is not supported for tables with FULLTEXT indexes. |
Rebuild with “null”ALTER |
Yes | Yes | Yes | Yes |
Uses ALGORITHM=INPLACE as of MySQL 5.6.17. ALGORITHM=COPY isused if old_alter_table=1 ormysqld --skip-new optionis enabled. Table rebuild using online DDL ( ALGORITHM=INPLACE )is not supported for tables with FULLTEXT indexes. |
实际测试中add primary key 和修改字段类型是需要copy tmp table的并且阻塞dml操作,另外在5.6.17版本之前时候用alter table table_name engine=innodb 是需要 copy table的并且也阻塞dml。
本来打算翻译成中文,后来发现这些英文实在是太简单了,就直接贴出来吧。
参考:http://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html#innodb-online-ddl-summary-grid