一次“诡异”的mysql死锁问题

下面是mysql error.log中有关死锁部分的信息:
2020-02-11T15:09:21.788043+08:00 2341233 [Note] InnoDB: Transactions deadlock detected, dumping detailed information.
2020-02-11T15:09:21.788055+08:00 2341233 [Note] InnoDB:
*** (1) TRANSACTION:

TRANSACTION 114340083, ACTIVE 0 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 4 lock struct(s), heap size 1136, 31 row lock(s), undo log entries 2
MySQL thread id 2341241, OS thread handle 140315515389696, query id 255909868 10.10.10.1 test updating
DELETE FROM TAB1 WHERE ID1 IS NULL AND ID2 IS NULL
2020-02-11T15:09:21.788078+08:00 2341233 [Note] InnoDB: *** (1) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 52 page no 314362 n bits 408 index ind_id1_id2 of table `db_test`.`tab1` trx id 114340083 lock_mode X waiting
Record lock, heap no 183 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: SQL NULL;
 1: SQL NULL;
 2: len 20; hex 3838383831383033303133383230363134303731; asc 88881803013820614071;;

2020-02-11T15:09:21.788149+08:00 2341233 [Note] InnoDB: *** (2) TRANSACTION:

TRANSACTION 114340084, ACTIVE 0 sec starting index read, thread declared inside InnoDB 1024
mysql tables in use 1, locked 1
8 lock struct(s), heap size 1136, 7 row lock(s), undo log entries 2
MySQL thread id 2341233, OS thread handle 140315530032896, query id 255909869 10.10.10.1 test updating
DELETE FROM TAB1 WHERE ID1 IS NULL AND ID2 IS NULL
2020-02-11T15:09:21.788166+08:00 2341233 [Note] InnoDB: *** (2) HOLDS THE LOCK(S):

RECORD LOCKS space id 52 page no 314362 n bits 408 index ind_id1_id2 of table `db_test`.`tab1` trx id 114340084 lock_mode X locks rec but not gap
Record lock, heap no 183 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: SQL NULL;
 1: SQL NULL;
 2: len 20; hex 3838383831383033303133383230363134303731; asc 88881803013820614071;;

2020-02-11T15:09:21.788235+08:00 2341233 [Note] InnoDB: *** (2) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 52 page no 314362 n bits 408 index ind_id1_id2 of table `db_test`.`tab1` trx id 114340084 lock_mode X waiting
Record lock, heap no 174 PHYSICAL RECORD: n_fields 3; compact format; info bits 32
 0: SQL NULL;
 1: SQL NULL;
 2: len 20; hex 3838383830383131303135393734313038303030; asc 88880811015974108000;;

2020-02-11T15:09:21.788296+08:00 2341233 [Note] InnoDB: *** WE ROLL BACK TRANSACTION (1)
关于死锁的日志信息,本来也并非罕见,但上面这段信息中,两个发生死锁的事务都只涉及到同样一条记录,也就是,两个事务都已经获取了同一个数据行上的锁,而且,
需要分别进一步获取彼此已持有的同一数据行上的锁,于是,就发生了死锁,最终,系统不得不把事务1给kill掉并进行了rollback。至此,大家是否觉得有点诡异呢?
这里,表tab1上除了有个主键id外,ind_id1_id2为次级索引,之所以发生如此奇怪的事情,都是因为null"惹的祸"。

你可能感兴趣的:(Mysql)