mysql8 Instant DDL 中间位置添加列

1. Instant DDL优点

The online DDL feature provides support for instant and in-place table alterations and concurrent DML. Benefits of this feature include:

  • Improved responsiveness and availability in busy production environments, where making a table unavailable for minutes or hours is not practical.
    在一个繁忙的系统上提高了响应性和可用性
  • For in-place operations, the ability to adjust the balance between performance and concurrency during DDL operations using the LOCK clause. See The LOCK clause.
  • Less disk space usage and I/O overhead than the table-copy method
    节约了磁盘IO

2. MySQL在8.0.12版本支持了Instant DDL功能

只需要修改数据字典的元数据,不需要修改存储层数据就可以快速完成DDL

ALTER TABLE *tbl_name* ADD COLUMN *column_name* *column_definition*, ALGORITHM=INSTANT;

支持的算法:

1.DEFAULT:MySQL自己选择锁定资源最少的方式

2.INSTANT:只需要更新数据字典中的元数据, 很快完成

3.INPLACE:在已存在的表空间文件内变更数据,除了一些特殊情况外表空间文件id 不会变化 此变更由InnoDB引擎独立完成, 不需要使用Redo log等, 可以节省开销

4.COPY:把存在数据拷贝到一个新的表空间文件中,所以IO 比较多,时间比较长 此变更会重建聚簇索引, 执行DDL的时候会创建临时表

快速DDL支持类型

  • Instant add column

    • 当一条alter语句中同时存在不支持instant的ddl时,则无法使用
    • 只能顺序加列,也就是说只能在最后添加列,这有点不友好,在8.0.29后可以任意地方加列
    • 不支持压缩表、不支持包含全文索引的表
    • 不支持临时表,临时表只能使用copy的方式执行DDL
    • 不支持那些在数据词典表空间中创建的表
  • 修改索引类型

  • 修改ENUM/SET类型的定义

    • 存储的大小不变时
    • 向后追加成员
  • 增加或删除类型为virtual的generated column

  • RENAME TABLE操作

3. MySQL 8.0.28版本增强Instant DDL对列重命名的支持

4. MySQL 8.0.29版本可以在任何地方添加列,而且是Instant,这个是个好特性

ALGORITHM=INSTANT Operations that support ALGORITHM=INSTANT only modify metadata in the data dictionary. No exclusive metadata locks(表级元数据锁) are taken on the table during preparation and execution phases of the operation, and table data is unaffected, making the operations instantaneous. If not specified explicitly, ALGORITHM=INSTANT is used by default by DDL operations that support it.

Prior to MySQL 8.0.29, an instantly added column could only be added as the last column of the table.
From MySQL 8.0.29, an instantly added column can be added to any position in the table.

Instantly added or dropped columns create a new row version. Up to 64 row versions are permitted. A new TOTAL_ROW_VERSIONS column was added to the INFORMATION_SCHEMA.INNODB_TABLES table to track the number of row versions.

参考文档:

官方文档 Functionality Added or Changed

官方文档 online ddl

数据库月刊3月

数据库月刊4月

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值