在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

如何理解MYSQL RC模式insert update可能死锁的情况

135次阅读
没有评论

共计 7987 个字符,预计需要花费 20 分钟才能阅读完成。

本篇文章给大家分享的是有关如何理解 MYSQL RC 模式 insert update 可能死锁的情况,丸趣 TV 小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着丸趣 TV 小编一起来看看吧。

涉及的语句为
RC 模式下
update 根据主键更新和 insert
其实这样的问题在 RC 模式下,要么是简单 update 问题,要么是 insert 造成的主键和唯一键检查唯一性时出现问题。
下面以主键问题为列子进行分析一下可能出现的情况。

update  where 条件更新为主键,锁结构出现在单行主键上,辅助索引包含隐含锁结构,当前读 RC 非唯一索引模式没有 GAP 锁,
insert   插入印象锁,主键和辅助索引上会出现隐含锁结构,

但是在 RC 模式下没有 GAP 所以插入印象锁一般不会成为问题

表结构:
+———+———————————————————————————————————————————————————————————–+
| Table   | Create Table                                                                                                                                                                      |
+———+———————————————————————————————————————————————————————————–+
| testlll | CREATE TABLE `testlll` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=latin1 |
+———+———————————————————————————————————————————————————————————–+

情况 1
insert
update

TX1:                                                                 TX2:
insert into testlll(name) values(gaopeng
                                                                          insert into testlll(name) values(gaopeng
update testlll set name= gaopeng1 where id=25;(堵塞)
                                                                           update testlll set name= gaopeng1 where id=24;(堵塞)
                                               
死锁

锁结构:

点击 (此处) 折叠或打开

—TRANSACTION 322809, ACTIVE 30 sec starting index read

mysql tables in use 1, locked 1

3 lock struct(s), heap size 1160, 2 row lock(s), undo log entries 1

MySQL thread id 3, OS thread handle 140734663714560, query id 409 localhost root updating

update testlll set name= gaopeng1 where id=24

—lock strcut(1):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

TABLE LOCK table `test`.`testlll` trx id 322809 lock mode IX

—lock strcut(2):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 322809 lock_mode X(LOCK_X) locks rec but not gap(LOCK_REC_NOT_GAP)

Record lock, heap no 25 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 80000019; asc ;;

 1: len 6; hex 00000004ecf9; asc ;;

 2: len 7; hex f0000001f90110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

—lock strcut(3):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 322809 lock_mode X(LOCK_X) locks rec but not gap(LOCK_REC_NOT_GAP) waiting(LOCK_WAIT)

Record lock, heap no 20 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 80000018; asc ;;

 1: len 6; hex 00000004ecf8; asc ;;

 2: len 7; hex ef000001f80110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

—TRANSACTION 322808, ACTIVE 43 sec starting index read

mysql tables in use 1, locked 1

LOCK WAIT 3 lock struct(s), heap size 1160, 2 row lock(s), undo log entries 1

MySQL thread id 2, OS thread handle 140734663980800, query id 408 localhost root updating

update testlll set name= gaopeng1 where id=25

——- TRX HAS BEEN WAITING 5 SEC FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 322808 lock_mode X(LOCK_X) locks rec but not gap(LOCK_REC_NOT_GAP) waiting(LOCK_WAIT)

Record lock, heap no 25 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 80000019; asc ;;

 1: len 6; hex 00000004ecf9; asc ;;

 2: len 7; hex f0000001f90110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

——————

—lock strcut(1):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

TABLE LOCK table `test`.`testlll` trx id 322808 lock mode IX

—lock strcut(2):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 322808 lock_mode X(LOCK_X) locks rec but not gap(LOCK_REC_NOT_GAP) waiting(LOCK_WAIT)

Record lock, heap no 25 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 80000019; asc ;;

 1: len 6; hex 00000004ecf9; asc ;;

 2: len 7; hex f0000001f90110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

—lock strcut(3):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 322808 lock_mode X(LOCK_X) locks rec but not gap(LOCK_REC_NOT_GAP)

Record lock, heap no 20 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 80000018; asc ;;

 1: len 6; hex 00000004ecf8; asc ;;

 2: len 7; hex ef000001f80110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

情况 2
update
update

TX1:                                                                  TX2:
update testlll set name= gaopeng1 where id=22;
                                                                           update testlll set name= gaopeng1 where id=25;
update testlll set name= gaopeng1 where id=25;(堵塞)
                                                                            update testlll set name= gaopeng1 where id=22;(堵塞)
死锁

这种情况比较简单不打印出锁结构

情况 3
insert
insert

TX1:                                                     TX2:
insert into testlll values(26, gaopeng
                                                             insert into testlll values(27, gaopeng
nsert into testlll values(27, gaopeng (堵塞)
                                                             insert into testlll values(26, gaopeng (堵塞)

死锁

锁结构:

点击 (此处) 折叠或打开

—TRANSACTION 422212176315800, not started

0 lock struct(s), heap size 1160, 0 row lock(s)

—TRANSACTION 323284, ACTIVE 10 sec inserting

mysql tables in use 1, locked 1

3 lock struct(s), heap size 1160, 2 row lock(s), undo log entries 1

MySQL thread id 2, OS thread handle 140734663980800, query id 369 localhost root update

insert into testlll values(26, gaopeng)

—lock strcut(1):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

TABLE LOCK table `test`.`testlll` trx id 323284 lock mode IX

—lock strcut(2):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 323284 lock_mode X(LOCK_X) locks rec but not gap(LOCK_REC_NOT_GAP)

Record lock, heap no 27 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 8000001b; asc ;;

 1: len 6; hex 00000004eed4; asc ;;

 2: len 7; hex d3000002a10110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

—lock strcut(3):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 323284 lock mode S(LOCK_S) locks rec but not gap(LOCK_REC_NOT_GAP) waiting(LOCK_WAIT)

Record lock, heap no 26 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 8000001a; asc ;;

 1: len 6; hex 00000004eed3; asc ;;

 2: len 7; hex d2000002330110; asc 3 ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

—TRANSACTION 323283, ACTIVE 14 sec inserting

mysql tables in use 1, locked 1

LOCK WAIT 3 lock struct(s), heap size 1160, 2 row lock(s), undo log entries 1

MySQL thread id 3, OS thread handle 140734663714560, query id 368 localhost root update

insert into testlll values(27, gaopeng)

——- TRX HAS BEEN WAITING 5 SEC FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 323283 lock mode S(LOCK_S) locks rec but not gap(LOCK_REC_NOT_GAP) waiting(LOCK_WAIT)

Record lock, heap no 27 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 8000001b; asc ;;

 1: len 6; hex 00000004eed4; asc ;;

 2: len 7; hex d3000002a10110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

——————

—lock strcut(1):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

TABLE LOCK table `test`.`testlll` trx id 323283 lock mode IX

—lock strcut(2):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 323283 lock mode S(LOCK_S) locks rec but not gap(LOCK_REC_NOT_GAP) waiting(LOCK_WAIT)

Record lock, heap no 27 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 8000001b; asc ;;

 1: len 6; hex 00000004eed4; asc ;;

 2: len 7; hex d3000002a10110; asc ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

—lock strcut(3):(Add by gaopeng) In modify Version I force check all REC_LOCK/TAB_LOCK for this Trx

RECORD LOCKS space id 434 page no 3 n bits 96 index PRIMARY of table `test`.`testlll` trx id 323283 lock_mode X(LOCK_X) locks rec but not gap(LOCK_REC_NOT_GAP)

Record lock, heap no 26 PHYSICAL RECORD: n_fields 4; compact format; info bits 0

 0: len 4; hex 8000001a; asc ;;

 1: len 6; hex 00000004eed3; asc ;;

 2: len 7; hex d2000002330110; asc 3 ;;

 3: len 7; hex 67616f70656e67; asc gaopeng;;

以上就是如何理解 MYSQL RC 模式 insert update 可能死锁的情况,丸趣 TV 小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计7987字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 美女视频一区二区三区在线 | 亚洲中文字幕无码天然素人在线 | 亚洲精品视频久久 | 免费看成人频视在线视频 | 欧美人在线一区二区三区 | 91免费国产在线观看 | 日日摸夜夜添夜夜添影院视频 | 无码一区二区三区视频 | 一级毛片免费不卡 | 日韩国产欧美精品综合二区 | 亚洲国产成人久久99精品 | 亚洲天堂福利 | 国产精品99爱免费视频 | 久久一区 | 国产成人一区二区三区影院免费 | 2019亚洲日韩新视频 | 很黄的网站在线观看 | 国产精品系列在线 | 欧美日韩另类国产 | 四虎影院在线免费播放 | 国产激情一级毛片久久久 | 一本大道在线无码一区 | 精品无码国产自产野外拍在线 | 久久成人免费观看草草影院 | 又黄又爽又色视频 | 免费看美女被靠到爽的视频 | 国产乱妇无乱码大黄aa片 | 国产精品视频h | 99这里有精品视频 | 亚洲乱码精品久久久久.. | 久久精品亚洲精品国产欧美 | 台湾swag在线视频 | 免费一级特黄欧美大片勹久久网 | 亚洲一区精品无码色成人 | 污污内射在线观看一区二区少妇 | 91精品酒店情侣在线播放 | 中文字幕亚洲欧美 | 99蜜桃臀久久久欧美精品网站 | 久久精品人妻无码一区二区三区 | 青草资源视频在线高清观看 | 香蕉视频地址 |