mysql gap锁 死锁_mysql事务死锁案例分析(GAP锁篇)

gap lock(间隙锁),主要用在mysql中解决RR级别事务隔离的幻读问题

下面是mysql对gap lock给出的官方解释:

A gap lock is a lock on a gap between index records, or a lock on the gap before the first or after the last index record。

在官方详细解析中有提到一个要点,也是导致本次事务死锁的根本原因

Gap locks in InnoDB are “purely inhibitive”, which means they only stop other transactions from inserting to the gap. They do not prevent different transactions from taking gap locks on the same gap. Thus, a gap X-lock has the same effect as a gap S-lock.

大致意思是:X-lock的gap和S-lock的效果是一样的,都是可以被多个事务获取到。

下面开始先分析gap lock 在唯一索引中的表现

表结构:

0818b9ca8b590ca3270a3433284dd417.png

建表sql

DROP TABLE IF EXISTS `staff_role_biz_role_id`;

CREATE TABLE `staff_role_biz_role_id` (

`

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值