码迷,mamicode.com
首页 > 数据库 > 详细

MySQL online ddl

时间:2014-12-26 14:55:21      阅读:198      评论:0      收藏:0      [点我收藏+]

标签: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 statement ALTER IGNORE TABLE t ADD UNIQUE INDEX does not delete duplicate rows. This has been reported as MySQL Bug #40344. The IGNORE keyword 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

实现过程:

技术分享技术分享

解决问题:

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_size3倍;

cRow Log Block大小,等于innodb_sort_buffer_size 

1.copy table online ddl

实现过程:

技术分享技术分享


本文出自 “My DBA life” 博客,请务必保留此出处http://huanghualiang.blog.51cto.com/6782683/1596174

MySQL online ddl

标签:mysql online ddl

原文地址:http://huanghualiang.blog.51cto.com/6782683/1596174

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!