在INNODB中的不同事务中从同一表中删除不同记录时遇到死锁

时间:2012-02-21 07:41:23

标签: mysql innodb deadlock

我曾遇到过以下死锁,并且对于为什么发生僵局感到非常困惑。

TRANSACTION(1) is running sql: 
delete from `test_STEP` where `test_C1`=865 

TRANSACTION(2) is running sql: 
delete from `test_STEP` where `test_C1`=866 

Column test_C1 has unique index named test_STEP_IDX. And the PRIMARY index is for another column named E_ID.

从死锁信息中,我们可以看到TRANSACTION(1)没有持有任何锁定但正在等待PRIMARY索引上的X模式下的某个记录锁定被授予。 TRANSACTION(2)PRIMARY索引上以X模式持有一些记录锁,包括TRANSACTION(1)正在等待的那个。并且TRANSACTION(2)仍在等待PRIMARY索引上的X模式中的另一个记录锁定。那令人困惑。究竟TRANSACTION(1)保持TRANSACTION(2)的持续时间是什么?

有人可以分享一下这个吗?提前致谢。

以下是“SHOW ENGINE INNODB STATUS \ G”显示的死锁信息。

------------------------ 
LATEST DETECTED DEADLOCK 
------------------------ 
120130 12:10:22 
*** (1) TRANSACTION: 
TRANSACTION A4CA, ACTIVE 1 sec fetching rows 
mysql tables in use 1, locked 1 
LOCK WAIT 9 lock struct(s), heap size 1248, 7 row lock(s), undo log entries 9 
MySQL thread id 27879, OS thread handle 0x4b52b940, query id 103192 qa64 10.101.7.27 hyang updating 
delete from `test_STEP` where `test_C1`=865 
*** (1) WAITING FOR THIS LOCK TO BE GRANTED: 
RECORD LOCKS space id 0 page no 7664 n bits 168 index `PRIMARY` of table ` abc`.`test_step` trx id A4CA lock_mode X locks rec but not gap waiting 
Record lock, heap no 67 PHYSICAL RECORD: n_fields 15; compact format; info bits 32 
0: len 8; hex 8000000000000ce5; asc ;; 
1: len 6; hex 00000000a4b5; asc ;; 
2: len 7; hex 150000015e1e80; asc ^ ;; 
3: len 30; hex 636f6d2e7478752e6d336f2e646372632e6e6f662e446372635374657054; asc ; (total 33 bytes); 
4: len 4; hex 80000000; asc ;; 
5: len 4; hex 80000001; asc ;; 
6: len 27; hex 5243202d204e6f74696669636174696f6e2047656e657261746564; asc RC - Notification Generated;; 
7: len 5; hex 456e646564; asc Ended;; 
8: len 8; hex 8000124c95356d3a; asc L 5m:;; 
9: len 8; hex 8000124c95356d3a; asc L 5m:;; 
10: len 4; hex 80000000; asc ;; 
11: SQL NULL; 
12: SQL NULL; 
13: len 8; hex 8000000000000362; asc b;; 
14: len 4; hex 80000000; asc ;; 

*** (2) TRANSACTION: 
TRANSACTION A4B5, ACTIVE 1 sec fetching rows 
mysql tables in use 1, locked 1 
12 lock struct(s), heap size 3112, 12 row lock(s), undo log entries 11 
MySQL thread id 27821, OS thread handle 0x4a8ba940, query id 102966 qa64 10.101.7.27 hyang updating 
delete from `test_STEP` where `test_C1`=866 
*** (2) HOLDS THE LOCK(S): 
RECORD LOCKS space id 0 page no 7664 n bits 192 index `PRIMARY` of table ` abc`.`test_step` trx id A4B5 lock_mode X locks rec but not gap 
Record lock, heap no 67 PHYSICAL RECORD: n_fields 15; compact format; info bits 32 
0: len 8; hex 8000000000000ce5; asc ;; 
1: len 6; hex 00000000a4b5; asc ;; 
2: len 7; hex 150000015e1e80; asc ^ ;; 
3: len 30; hex 636f6d2e7478752e6d336f2e646372632e6e6f662e446372635374657054; asc ; (total 33 bytes); 
4: len 4; hex 80000000; asc ;; 
5: len 4; hex 80000001; asc ;; 
6: len 27; hex 5243202d204e6f74696669636174696f6e2047656e657261746564; asc RC - Notification Generated;; 
7: len 5; hex 456e646564; asc Ended;; 
8: len 8; hex 8000124c95356d3a; asc L 5m:;; 
9: len 8; hex 8000124c95356d3a; asc L 5m:;; 
10: len 4; hex 80000000; asc ;; 
11: SQL NULL; 
12: SQL NULL; 
13: len 8; hex 8000000000000362; asc b;; 
14: len 4; hex 80000000; asc ;; 

Record lock, heap no 68 PHYSICAL RECORD: n_fields 15; compact format; info bits 32 
0: len 8; hex 8000000000000ce6; asc ;; 
1: len 6; hex 00000000a4b5; asc ;; 
2: len 7; hex 150000015e1ec1; asc ^ ;; 
3: len 30; hex 636f6d2e7478752e6d336f2e646372632e6e6f662e446372635374657054; asc ; (total 33 bytes); 
4: len 4; hex 80000000; asc ;; 
5: len 4; hex 80000002; asc ;; 
6: len 22; hex 5243202d205061796d656e7420746f204d61726b6574; asc RC - Payment to Market;; 
7: len 7; hex 53746172746564; asc Started;; 
8: len 8; hex 8000124c95356d3a; asc L 5m:;; 
9: SQL NULL; 
10: SQL NULL; 
11: SQL NULL; 
12: SQL NULL; 
13: len 8; hex 8000000000000362; asc b;; 
14: len 4; hex 80000001; asc ;; 

Record lock, heap no 96 PHYSICAL RECORD: n_fields 15; compact format; info bits 0 
0: len 8; hex 8000000000000d03; asc ;; 
1: len 6; hex 00000000a4b5; asc ;; 
2: len 7; hex 950000015f0110; asc _ ;; 
3: len 30; hex 636f6d2e7478752e6d336f2e646372632e6e6f662e446372635374657054; asc ; (total 33 bytes); 
4: len 4; hex 80000000; asc ;; 
5: len 4; hex 80000001; asc ;; 
6: len 27; hex 5243202d204e6f74696669636174696f6e2047656e657261746564; asc RC - Notification Generated;; 
7: len 5; hex 456e646564; asc Ended;; 
8: len 8; hex 8000124c95356d3a; asc L 5m:;; 
9: len 8; hex 8000124c95356d3a; asc L 5m:;; 
10: len 4; hex 80000000; asc ;; 
11: SQL NULL; 
12: SQL NULL; 
13: SQL NULL; 
14: SQL NULL; 

Record lock, heap no 97 PHYSICAL RECORD: n_fields 15; compact format; info bits 0 
0: len 8; hex 8000000000000d04; asc ;; 
1: len 6; hex 00000000a4b5; asc ;; 
2: len 7; hex 950000015f0121; asc _ !;; 
3: len 30; hex 636f6d2e7478752e6d336f2e646372632e6e6f662e446372635374657054; asc ; (total 33 bytes); 
4: len 4; hex 80000000; asc ;; 
5: len 4; hex 80000002; asc ;; 
6: len 22; hex 5243202d205061796d656e7420746f204d61726b6574; asc RC - Payment to Market;; 
7: len 7; hex 53746172746564; asc Started;; 
8: len 8; hex 8000124c95356d3a; asc L 5m:;; 
9: SQL NULL; 
10: SQL NULL; 
11: SQL NULL; 
12: SQL NULL; 
13: SQL NULL; 
14: SQL NULL; 

Record lock, heap no 98 PHYSICAL RECORD: n_fields 15; compact format; info bits 0 
0: len 8; hex 8000000000000d05; asc ;; 
1: len 6; hex 00000000a4b5; asc ;; 
2: len 7; hex 950000015f0132; asc _ 2;; 
3: len 30; hex 636f6d2e7478752e6d336f2e646372632e6e6f662e446372635374657054; asc ; (total 33 bytes); 
4: len 4; hex 80000000; asc ;; 
5: len 4; hex 80000003; asc ;; 
6: len 25; hex 5243202d2053776974636820446f632047656e657261746564; asc RC - Switch Doc Generated;; 
7: len 7; hex 53746172746564; asc Started;; 
8: len 8; hex 8000124c95356d3c; asc L 5m<;; 
9: SQL NULL; 
10: SQL NULL; 
11: SQL NULL; 
12: SQL NULL; 
13: SQL NULL; 
14: SQL NULL; 

*** (2) WAITING FOR THIS LOCK TO BE GRANTED: 
RECORD LOCKS space id 0 page no 7664 n bits 168 index `PRIMARY` of table ` abc`.`test_step` trx id A4B5 lock_mode X locks rec but not gap waiting 
Record lock, heap no 99 PHYSICAL RECORD: n_fields 15; compact format; info bits 0 
0: len 8; hex 8000000000000d06; asc ;; 
1: len 6; hex 00000000a4ca; asc ;; 
2: len 7; hex a800001bcc0110; asc ;; 
3: len 30; hex 636f6d2e7478752e6d336f2e646372632e6e6f662e446372635374657054; asc ; (total 33 bytes); 
4: len 4; hex 80000000; asc ;; 
5: len 4; hex 80000001; asc ;; 
6: len 27; hex 5243202d204e6f74696669636174696f6e2047656e657261746564; asc RC - Notification Generated;; 
7: len 5; hex 456e646564; asc Ended;; 
8: len 8; hex 8000124c95356d3a; asc L 5m:;; 
9: len 8; hex 8000124c95356d3a; asc L 5m:;; 
10: len 4; hex 80000000; asc ;; 
11: SQL NULL; 
12: SQL NULL; 
13: SQL NULL; 
14: SQL NULL; 

*** WE ROLL BACK TRANSACTION (1)

0 个答案:

没有答案