当前位置:网站首页>MySQL加索引语句不加锁:ALGORITHM=INPLACE, LOCK=NONE
MySQL加索引语句不加锁:ALGORITHM=INPLACE, LOCK=NONE
2022-06-30 07:54:00 【飘然渡沧海】
线上无锁添加索引:加索引的语句不加锁
ALTER TABLE tbl_name ADD PRIMARY KEY (column), ALGORITHM=INPLACE, LOCK=NONE;
ALGORITHM=INPLACE
更优秀的解决方案,在当前表加索引,步骤:
1.创建索引(二级索引)数据字典
2.加共享表锁,禁止DML,允许查询
3.读取聚簇索引,构造新的索引项,排序并插
入新索引
4.等待打开当前表的所有只读事务提交
5.创建索引结束
ALGORITHM=COPY
通过临时表创建索引,需要多一倍存储,还有更多的IO,步骤:
1.新建带索引(主键索引)的临时表
2.锁原表,禁止DML,允许查询
3.将原表数据拷贝到临时表
4.禁止读写,进行rename,升级字典锁
5.完成创建索引操作
LOCK=DEFAULT:默认方式,MySQL自行判断使用哪种LOCK模式,尽量不锁表
LOCK=NONE:无锁:允许Online DDL期间进行并发读写操作。如果Online DDL操
作不支持对表的继续写入,则DDL操作失败,对表修改无效
LOCK=SHARED:共享锁:Online DDL操作期间堵塞写入,不影响读取
LOCK=EXCLUSIVE:排它锁:Online DDL操作期间不允许对锁表进行任何操作
然后在阿里云的帮助上找到了一个解决方法
- In-Place?:对应 DDL语句的 Algorithm 选项,通过 inplace 方式执行 DDL。相比表拷贝方式,可以减少空间和 I/O 消耗。
- Copies Table?:对应 DDL语句的 Algorithm 选项,通过 表拷贝 方式执行 DDL。DDL 执行期间会占用更大的磁盘空间和消耗更多的 I/O。
- 允许并发 DML?:对应 DDL语句的 Lock 选项,DDL 执行期间是否支持并发 DML 操作。
- 允许并发查询?:DDL 语句执行期间是否支持并发查询操作(通常都是支持的)。
- MySQL官方文档请参考:Online DDL 概览
- DDL 操作执行时需要修改表的元数据(metadata),有可能会遇到等待表元数据锁的情况(waiting for table metadata lock),该情况的处理方式请参考:RDS MySQL 表上 Metadata lock 的产生和处理
- Inplace 和 Copy Table 是相反的 2 种处理方式;但即使 DDL 支持 Inplace 选项,某些操作在整个执行过程中也会部分涉及到表拷贝,比如上表中的添加列操作。
边栏推荐
- 2021 private equity fund market report (62 pages)
- Firewall firewalld
- More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
- Personal blog one article multi post tutorial - basic usage of openwriter management tool
- HelloWorld
- Hit the industry directly | the flying propeller launched the industry's first model selection tool
- 深度学习——特征点检测和目标检测
- Analysis of cross clock transmission in tinyriscv
- Basic theory of four elements and its application
- At the end of June, you can start to make preparations, otherwise you won't have a share in such a profitable industry
猜你喜欢

Final review -php learning notes 2-php language foundation

Efga design open source framework fabulous series (I) establishment of development environment

The counting tool of combinatorial mathematics -- generating function

Deep learning - brnn and DRNN

1162 Postfix Expression

期末复习-PHP学习笔记1
![2021-10-29 [microbiology] qiime2 sample pretreatment form automation script](/img/4d/3a3d645a27c3561c3ebe20dcd8e142.jpg)
2021-10-29 [microbiology] qiime2 sample pretreatment form automation script

6月底了,可以开始做准备了,不然这么赚钱的行业就没你的份了

2021 private equity fund market report (62 pages)
![November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)](/img/0d/77953ffa9f45a5acc16f02bf33293b.jpg)
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)
随机推荐
25岁,从天坑行业提桶跑路,在经历千辛万苦转行程序员,属于我的春天终于来了
深度学习——LSTM
1162 Postfix Expression
多快好省,低门槛AI部署工具FastDeploy测试版来了!
November 19, 2021 [reading notes] a summary of common problems of sneakemake (Part 2)
Go 数据类型篇之字符串及底层字符类型
深度学习——Bounding Box预测
深度学习——目标定位
Halcon12+vs2013 C # configuration
NMOS model selection
January 23, 2022 [reading notes] - bioinformatics and functional genomics (Chapter 6: multiple sequence alignment)
Projection point of point on line
Deep learning - brnn and DRNN
【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
深度学习——网络中的网络以及1x1卷积
Hit the industry directly | the flying propeller launched the industry's first model selection tool
Introduction notes to pytorch deep learning (XII) neural network - nonlinear activation
Simple application of generating function
【花雕体验】14 行空板pinpong库测试外接传感器模块(之一)
回文子串、回文子序列