当前位置:Gxlcms > 数据库问题 > MySQL死锁分析一例

MySQL死锁分析一例

时间:2021-07-01 10:21:17 帮助过:34人阅读


mysql tables in use 1, locked 1
LOCK WAIT 2183 lock struct(s), heap size 407992, 145 row lock(s), undo log entries 8
MySQL thread id 20259, OS thread handle 0x189c, query id 276602977 localhost 127.0.0.1 root updating
delete from a93 where patientId=164136 and count=9
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 4609 page no 4 n bits 136 index `PRIMARY` of table `emr_new2`.`a93` trx id 2067C318 lock_mode X locks rec but not gap waiting
Record lock, heap no 4 PHYSICAL RECORD: n_fields 71; compact format; info bits 0

 

*** (2) TRANSACTION:
TRANSACTION 2067C43F, ACTIVE 7 sec fetching rows, thread declared inside InnoDB 424
mysql tables in use 1, locked 1
2223 lock struct(s), heap size 440760, 192 row lock(s), undo log entries 8
MySQL thread id 20135, OS thread handle 0xf28, query id 276602976 localhost 127.0.0.1 root updating
delete from a93 where patientId=164136 and count=9
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 4609 page no 4 n bits 136 index `PRIMARY` of table `emr_new2`.`a93` trx id 2067C43F lock_mode X locks rec but not gap
Record lock, heap no 4 PHYSICAL RECORD: n_fields 71; compact format; info bits 0

可以看到两个事务 TRANSACTION 2067C318 和 TRANSACTION 2067C43F 分别执行: delete from a93 wehre patientId=164136 and count=9 

导致了相互等待。

查看表结构和数据量,发现 patientId未加索引,数据量很大,导致delete语句会全表扫描,容易长时间持有锁。

加上索引: alter table a93 add index patientId(patientId);

 

 

  

 

MySQL死锁分析一例

标签:show   row   事务   fetching   com   tran   相互   highlight   inf   

人气教程排行