前言
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 | |
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_FORMAT property |
Yes | Yes | Yes | Yes | Although ALGORITHM=INPLACE is allowed, the data is reorganized substantially, so it is still an expensive operation. |
ChangeKEY_BLOCK_SIZE property |
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 5.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 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 |
No | Yes | No | Yes | Acts like the ALGORITHM=COPY clause or the setting old_alter_table=1 . |
LOCK=
ALGORITHM=[INPLACE|COPY]
innodb_online_alter_log_max_size 需要注意,它表示在做在线DDL的过程中,并发DML产生的日志最大允许的大小。如果负载很高,这个值应该尽量的调大,否则可能导致DDL失败。
性能损耗
无压力负载测试:
mysql> set session old_alter_table = OFF;
Query OK, 0 rows affected (0.00 sec)
mysql> alter table sbtest1 add key (k);
Query OK, 0 rows affected (10.44 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table sbtest1 drop key k;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table sbtest1 add key(k), ALGORITHM=COPY;
Query OK, 1000000 rows affected (27.72 sec)
Records: 1000000 Duplicates: 0 Warnings: 0
mysql> alter table sbtest1 drop key k;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table sbtest1 add key(k), LOCK=SHARED;
Query OK, 0 rows affected (9.89 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table sbtest1 drop key k;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table sbtest1 add key(k), LOCK=EXCLUSIVE;
Query OK, 0 rows affected (10.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
内部实现
8031 &ha_alter_info);
6391 goto rollback;
6392 }
6422 goto rollback;
6423 }
6449 {
6450 goto rollback;
6451 }
原创文章,转载请注明: 转载自Simple Life
本文链接地址: [MySQL 5.6] MySQL 5.6 online ddl 使用、测试及关键函数栈