MySQL5.6 Online DDL 是否锁表、rebuild表、inplace的说明

Online DDL 是否锁表、是否rebuild表、inplace或copy算法的说明:

原文: https://dev.mysql.com/doc/refman/5.6/en/innodb-create-index-overview.html?spm=5176.100239.blogcont64664.13.SpL8lH

Operation In-Place? Rebuilds Table? Permits Concurrent DML? Only Modifies Metadata? Notes
CREATE INDEXADD INDEX Yes* No* Yes No Restrictions apply for FULLTEXT indexes; see next row.
ADD FULLTEXT INDEX Yes* No* No No Adding the first FULLTEXT index rebuilds the table if there is no user-defined FTS_DOC_ID column. Subsequent FULLTEXT indexes may be added on the same table without rebuilding the table.
DROP INDEX Yes No Yes Yes Only modifies table metadata.
OPTIMIZE TABLE Yes* Yes Yes No Performed in-place as of MySQL 5.6.17. In-place operation is not supported for tables withFULLTEXT indexes.
Set column default value Yes No Yes Yes Only modifies table metadata.
Change auto-incrementvalue Yes No Yes No* Modifies a value stored in memory, not the data file.
Add foreign key constraint Yes* No Yes Yes The INPLACE algorithm is supported when foreign_key_checks is disabled. Otherwise, only theCOPY algorithm is supported.
Drop foreign key constraint Yes No Yes Yes foreign_key_checks can be enabled or disabled.
Rename column Yes No Yes* Yes To permit concurrent DML, keep the same data type and only change the column name.
Add column Yes Yes Yes* No Concurrent DML is not permitted when adding an auto-increment column. Data is reorganized substantially, making it an expensive operation.
Drop column Yes Yes Yes No Data is reorganized substantially, making it an expensive operation.
Reorder columns Yes Yes Yes No Data is reorganized substantially, making it an expensive operation.
Change ROW_FORMATproperty Yes Yes Yes No Data is reorganized substantially, making it an expensive operation.
Change KEY_BLOCK_SIZEproperty Yes Yes Yes No Data is reorganized substantially, making it an expensive operation.
Make column NULL Yes Yes* Yes No Rebuilds the table in place. Data is reorganized substantially, making it an expensive operation.
Make column NOT NULL Yes* Yes* Yes No Rebuilds the table in place. STRICT_ALL_TABLES or STRICT_TRANS_TABLES SQL_MODE is required for the operation to succeed. The operation fails if the column contains NULL values. As of 5.6.7, the server prohibits changes to foreign key columns that have the potential to cause loss of referential integrity. See Section 13.1.7, “ALTER TABLE Syntax”. Data is reorganized substantially, making it an expensive operation.
Change column data type No Yes No No Only supports ALGORITHM=COPY
Add primary key Yes* Yes* Yes No Rebuilds the table in place. Data is reorganized substantially, making it an expensive operation.ALGORITHM=INPLACE is not permitted under certain conditions if columns have to be converted toNOT NULL.
Drop primary key and add another Yes Yes Yes No Data is reorganized substantially, making it an expensive operation.
Drop primary key No Yes No No Only ALGORITHM=COPY supports dropping a primary key without adding a new one in the sameALTER TABLE statement.
Convert character set No Yes* No No Rebuilds the table if the new character encoding is different.
Specify character set No Yes* No No Rebuilds the table if the new character encoding is different.
Rebuild with FORCEoption Yes* Yes Yes No Uses ALGORITHM=INPLACE as of MySQL 5.6.17. ALGORITHM=INPLACE is not supported for tables withFULLTEXT indexes.
“null” rebuild usingALTER TABLE ... ENGINE=INNODB Yes* Yes Yes No Uses ALGORITHM=INPLACE as of MySQL 5.6.17. ALGORITHM=INPLACE is not supported for tables withFULLTEXT indexes.
Set STATS_PERSISTENT,STATS_AUTO_RECALC,STATS_SAMPLE_PAGESpersistent statisticsoptions Yes No Yes Yes Only modifie

其余可参考文章: https://yq.aliyun.com/articles/64664

时间: 2024-07-30 05:01:12

MySQL5.6 Online DDL 是否锁表、rebuild表、inplace的说明的相关文章

MySQL5.6在线DDL不锁表(在线添加字段)

MySQL5.6在线DDL不锁表(在线添加字段) 解答你也看一下MySQL5.6在线DDL不锁表,现在我有一张1亿的表,需要增加一个字段,假如我让你去增加这个字段,你应该注意什么,具体怎么操作? 操作如下:1.注意磁盘空间(临时表目录)2.当前内存剩余量3.当前有没有大的事务在执行4.innodb_online_alter_log_max_size参数5.然后在从上添加,再在主上添加(不记录binlog),处理完成后再开启 如果直接先在主上操作,那么会导致主从延迟很大(在量比较大的情况下).因为

MySQL5.7—在线DDL总结

---切记:DDL操作要在业务低峰期进行 1.MySQL各版本,对于DDL的处理方式是不同的,主要有三种: ①:Copy Table方式: 这是InnoDB最早支持的方式.顾名思义,通过临时表拷贝的方式实现的.新建一个带有新结构的临时表,将原表数据全部拷贝到临                    时表,然后Rename,完成创建操作.这个方式过程中,原表是可读的,不可写.但是会消耗一倍的存储空间. ②:Inplace方式:这是原生MySQL 5.5,以及innodb_plugin中提供的方式.

Mysql5.6 online ddl

Innodb性能改善方面: --Users can add indexes and perform standard table alterations while the database remains available for application updates. 支持在线操作(add index.alter table): 例子一:在线添加索引:开启一个session,对italk库下的data_userinfo表做创建索引的操作,(该表大概70万数据):mysql>>creat

MySQL锁系列2 表锁

上一篇介绍了MySQL源码中保护内存结构或变量的锁,这里开始介绍下MySQL事务中的表锁. 注1: 在表锁的实现上面,使用[mutex+condition+queue]的结构实现并发,阻塞,唤醒的表锁功能. 注2: 本文进行的一些实验,重要的配置项: 1. autocommit=0 2. tx_isolation=read-commited 3. engine=innodb 1. MySQL加锁的顺序: 这里包括了一个sql在执行的过程中,包括commit,所添加和释放跟事务相关的锁以及加不同锁

06 | 全局锁和表锁 :给表加个字段怎么有这么多阻碍?

今天我要跟你聊聊MySQL的锁.数据库锁设计的初衷是处理并发问题.作为多用户共享的资源,当出现并发访问的时候,数据库需要合理地控制资源的访问规则.而锁就是用来实现这些访问规则的重要数据结构. 根据加锁的范围,MySQL里面的锁大致可以分成全局锁.表级锁和行锁三类.今天这篇文章,我会和你分享全局锁和表级锁.而关于行锁的内容,我会留着在下一篇文章中再和你详细介绍. 这里需要说明的是,锁的设计比较复杂,这两篇文章不会涉及锁的具体实现细节,主要介绍的是碰到锁时的现象和其背后的原理. 全局锁 顾名思义,全

查看Oracle数据库被锁住的表,删除锁表的进程

锁表处理及查询 查看Oracle数据库被锁住的表,删除锁表的进程 1.查看被锁住的表 SELECT dob.object_name table_name,    lo.locked_mode, lo.session_id, vss.serial#, vss.action action, vss.osuser osuser, vss.logon_time, vss.process ap_pid, vps.spid db_pid FROM v$locked_object lo, dba_object

[转]查看处于被锁状态的表:v$locked_object dba_objects v$session all_objects v$sqlarea v$lock

oracle官网当一个用户发出select..for update的错作准备对返回的结果集进行修改时,如果结果集已经被另一个会话锁定,就是发生阻塞.需要等另一个会话结束之后才可继续执行.可以通过发出 select… for update nowait的语句来避免发生阻塞,如果资源已经被另一个会话锁定,则会返回以下错误:Ora-00054:resource busy and acquire with nowait specified. oracle官网死锁-deadlock 定义:当两个用户希望持

一个高性能无锁哈希表的设计和实现

无锁哈希表(Lock-Free Hash Table)是多线程编程中的理想数据结构,但是实现以及使用都需要一定的技巧.作者对此做了一个巧妙的设计实现,在现代X86平台上能取得千万次每秒的并发查找/增加/删除操作. 通过考察各种基于CAS原子操作的无锁数据结构实现,目前公认可实现无锁安全的数据结构是数组和单向队列.其他实现都一定程度上受到ABA问题的威胁.数组的实现相对于单向队列要简单,所以无锁hash table理想的选择是数组,对于冲突不拉链.但是如何解决hash冲突呢?基本思想依然是开放寻址

mysql 开发进阶篇系列 13 锁问题(关于表锁,死锁示例,锁等待设置)

一. 什么时候使用表锁 对于INNODB表,在绝大部分情况下都应该使用行锁.在个别特殊事务中,可以考虑使用表锁(建议). 1. 事务需要更新大部份或全部数据,表又比较大,默认的行锁不仅使这个事务执行效率低,可能造成其他事务长时间锁等待和锁冲突,这种情况考虑使用表锁来提高事务的执行速度(具我在sql server中的经历,该大表有上100w,删除40w,表锁有时会造成长时间未执行完成. 还是使用分批来执行好). 2. 事务涉及多个表,比较复杂,很可能引起死锁,造成大量事务回滚.这种情况可以考虑一次