我有一个带有MySQL数据库引擎的运行系统。
运行SHOW ENGINE INNODB STATUS
命令会显示:
------------------------
LATEST DETECTED DEADLOCK
------------------------
*** (1) TRANSACTION:
UPDATE db.alarm
LEFT JOIN (db.event, db.alarm1)
ON db.event.idevent = db.alarm.idevent
AND db.alarm1.idevent = db.alarm.idevent
SET
idalarmseverity = NAME_CONST('alarmseveritycleared',1),
lastmodifieddate = NAME_CONST('moddate',_binary'2015-01-07 09:02:00' COLLATE 'binary')
WHERE db.event.ideventsource = NAME_CONST('sourceid',3)
AND (db.alarm1.idorder = NAME_CONST('orderid',18894) OR NAME_CONST('orderid',18894) = 0)
AND db.alarm.idalarmseverity > 1
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 32942 n bits 440 index `GEN_CLUST_INDEX` of table `db`.`alarm` trx id 17 2553624600 lock_mode X locks rec but not gap waiting
*** (2) TRANSACTION:
UPDATE db.alarm
LEFT JOIN (db.event, db.alarm2)
ON db.event.idevent=db.alarm.idevent
AND db.alarm2.idevent=db.alarm.idevent
SET
idalarmseverity= NAME_CONST('alarmseveritycleared',1),
lastmodifieddate= NAME_CONST('moddate',_binary'2015-01-07 09:02:00' COLLATE 'binary')
WHERE db.event.ideventsource= NAME_CONST('sourceid',3)
AND db.alarm.idalarmseverity > 1
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 0 page no 32942 n bits 440 index `GEN_CLUST_INDEX` of table `db`.`alarm` trx id 17 2553624599 lock_mode X locks rec but not gap
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 32941 n bits 440 index `GEN_CLUST_INDEX` of table `db`.`alarm` trx id 17 2553624599 lock_mode X locks rec but not gap waiting
此时我不知道第二次TRANSACTION正在等待什么。
第一个交易正在等待第二个交易持有的锁定(第32942页)。这很清楚 但是第二笔交易正在等待锁定(第32941页),这是任何人都没有的。
或者2个锁是否与当前持有锁的同一事务相同(或重叠)。我不太了解它,所以如果有人可以向我解释这个死锁是如何发生的,以及如何修改UPDATE以防止将来出现这样的死锁,那将会很棒。
由于