MySQL DDL锁表情况分析

发布时间:2021-08-31 23:09:36 作者:chen
来源:亿速云 阅读:207

这篇文章主要介绍“MySQL DDL锁表情况分析”,在日常操作中,相信很多人在MySQL DDL锁表情况分析问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”MySQL DDL锁表情况分析”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

版本5.7.22,隔离级别RR

当DDL的表存在慢查询时,此时对该表做DDL,由于无法获得metadata锁,所以会等待该锁,造成锁表,后续DML操作全部进入等待状态。
session1:
MySQL DDL锁表情况分析
session2:
MySQL DDL锁表情况分析
session3:
MySQL DDL锁表情况分析
session4:
MySQL DDL锁表情况分析

MySQL DDL锁表情况分析

tips:
select sleep(N) from t;表示查询t的时间为t中的行数*N,如下:
MySQL DDL锁表情况分析

Before an online DDL operation can finish, it must wait for transactions that hold metadata locks on the table to commit or roll back. An online DDL operation may briefly require an exclusive metadata lock on the table during its execution phase, and always requires one in the final phase of the operation when updating the table definition. Consequently, transactions holding metadata locks on the table can cause an online DDL operation to block. The transactions that hold metadata locks on the table may have been started before or during the online DDL operation. A long running or inactive transaction that holds a metadata lock on the table can cause an online DDL operation to timeout.
在线DDL操作完成之前,必须等待持有表上的元数据锁的事务提交或回滚。在线DDL操作在执行阶段可能会短暂地需要表上的独占元数据锁,并且在更新表定义时总是在操作的最后阶段需要一个锁。因此,持有表上的元数据锁的事务可能导致在线DDL操作阻塞。表上持有元数据锁的事务可能在DDL在线操作之前或期间启动。在表上持有元数据锁的长时间运行或不活动的事务可能导致在线DDL操作超时。
https://dev.mysql.com/doc/refman/5.6/en/innodb-online-ddl-limitations.html
Online DDL and Metadata Locks
Online DDL operations can be viewed as having three phases:    DDL的在线操作可以分为三个阶段:

到此,关于“MySQL DDL锁表情况分析”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. MySQL数据库中DDL语句的介绍和使用
  2. MySQL5.6在线表结构变更(online ddl)总结

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql

上一篇:3种CQRS架构模式介绍

下一篇:C++的类与C#的类详细介绍

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》