现在的位置: 首页 > 综合 > 正文

关于mysql 5.6 哪些操作可以进行online ddl 详解

2018年01月21日 ⁄ 综合 ⁄ 共 3881字 ⁄ 字号 评论关闭

 Summary of Online Status for DDL Operations

Operation In-Place? Copies Table? Allows Concurrent DML? Allows Concurrent Query? Notes
CREATE
INDEX
,ADD
INDEX
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 sameALTER
TABLE
 statement.
ADD
FULLTEXT INDEX
Yes No* No Yes Creating the first FULLTEXT index for a table involves
a table copy, unless there is a user-supplied FTS_DOC_ID column.
Subsequent FULLTEXT indexes on the same table can be created
in-place.
DROP
INDEX
Yes No Yes Yes  
OPTIMIZE
TABLE
Yes Yes Yes Yes Uses ALGORITHM=INPLACE as of MySQL 5.6.17. ALGORITHM=COPY is
used if old_alter_table=1 ormysqld --skip-new option
is 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 during
constraint creation.
Drop a foreign
key constraint
Yes No Yes Yes The foreign_key_checks option
can 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 reorganized
substantially, so it is still an expensive operation.
Drop a column Yes Yes Yes Yes Although ALGORITHM=INPLACE is allowed, the data is reorganized
substantially, so it is still an expensive operation.
Reorder columns Yes Yes Yes Yes Although ALGORITHM=INPLACE is allowed, the data is reorganized
substantially, so it is still an expensive operation.
ChangeROW_FORMATproperty Yes Yes Yes Yes Although ALGORITHM=INPLACE is allowed, the data is reorganized
substantially, so it is still an expensive operation.
ChangeKEY_BLOCK_SIZEproperty Yes Yes Yes Yes Although ALGORITHM=INPLACE is allowed, the data is reorganized
substantially, so it is still an expensive operation.
Make columnNULL Yes Yes Yes Yes Although ALGORITHM=INPLACE is allowed, the data is reorganized
substantially, 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 is
allowed, 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 reorganized
substantially, so it is still an expensive operation. ALGORITHM=INPLACE is
not allowed under certain conditions if columns have to be converted to NOT
NULL
. See Example 14.9,
“Creating and Dropping the Primary Key”
.
Drop primary
key
and add another
Yes Yes Yes Yes ALGORITHM=INPLACE is only allowed when you add a new primary
key in the same ALTER
TABLE
; 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
TABLE
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 is
used if old_alter_table=1 ormysqld --skip-new option
is enabled. Table rebuild using online DDL (ALGORITHM=INPLACE)
is not supported for tables with FULLTEXT indexes.
Rebuild with nullALTER
TABLE ... ENGINE=INNODB
Yes Yes Yes Yes Uses ALGORITHM=INPLACE as of MySQL 5.6.17. ALGORITHM=COPY is
used if old_alter_table=1 ormysqld --skip-new option
is 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

抱歉!评论已关闭.