mysql 5.6 online ddl_MySQL online ddl

前言:

5.1 和 5.5 innodb plugin 支持Fast index create:

Fast index create 如何实现的? 只是对于 secondary index ,不需要copy table data。

执行过程:

1.判断当前表是否有未结束的transaction(commit or rollback)

2.对原表加 shared lock

2.把secondary index 用的column 排序放到memory或temp file,建立B-Tree 索引

3.unlock table

注意每一次create index 或 alter table add index 都会扫描一次clustered index,所以尽量把多个添加索引语句放在一起。

alter table xxx drop index xx_idx1,add index xx_idx2,add index xx_idx3;

Fast index create的限制:

1.新的索引,临时文件写入tempdir。

2.alter table drop index name_idx,add index name_idx;使用的是同一个索引名,使用copy table data。

3.TEMPORARY TABLE创建index使用copy table data。

4.ALTER TABLE ... RENAME COLUMN 为了保证innodb的数据字典和mysql的数据字典信息保持一致,使用copy table data

5.The statementALTER IGNORE TABLE t ADD UNIQUE INDEXdoes not delete duplicate rows. This has been reported as MySQL Bug #40344. TheIGNOREkeyword is ignored. If any duplicate rows exist, the operation fails with the following error message:ERROR 23000: Duplicate entry '347' for key 'pl'

6.optimize table 更新secondary index 不用使用Fast index create。

DDL发展历程:

1.copy table

MySQL最早的DDL操作方式,DDL通过Copy Table方式实现:

-新建temp table

-锁住原表,原表可读不可写

-copy原表的数据到tempbiao

-删除原表,rename temp表

2.inplace

-在原表上直接进行ddl,锁表进行

缺点:并发度低

3.online

ddl过程不长期锁表,并发读写

1.inplace online ddl

2.copy table online ddl

二.从5.6 开始,支持Online DDL(inplace online ddl、copy table online ddl)

1.inplace online ddl

实现过程:

spacer.gif90940e328839fd9eae0f7b5bc881e4a0.png

解决问题:

1.online ddl 过程中,add index,因缺乏新的索引,索引字典上新增一个标识:trx_id(代表索引创建过程最大的事务id),小于此trx_id的事务都不使用新索引。

2.优化(加速)Online DDL的性能:

a可通过增加innodb_sort_buffer_size参数,优化Online (Add Index/Column)操作性能;

b创建索引,排序过程,使用内存大小为innodb_sort_buffer_size的3倍;

cRow Log Block大小,等于innodb_sort_buffer_size ;

1.copy table online ddl

实现过程:

spacer.gif4649751677b94eb359f85638257450ec.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值