Hi, all
I met the following deadlock once and was very confusing about why the deadlock happened.
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.
From the deadlock info, we could see that TRANSACTION(1) wasn't holding any lock but was waiting for PRIMARY index lock to be granted. TRANSACTION(2) was holding a PRIMARY index lock and still waiting for PRIMARY index lock. That was so confusing. What exactly TRANSACTION(1) hold and kept TRANSACTION(2) from going on?
Could anybody share some light about this? Thanks in advanced.
------------------------
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)
I met the following deadlock once and was very confusing about why the deadlock happened.
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.
From the deadlock info, we could see that TRANSACTION(1) wasn't holding any lock but was waiting for PRIMARY index lock to be granted. TRANSACTION(2) was holding a PRIMARY index lock and still waiting for PRIMARY index lock. That was so confusing. What exactly TRANSACTION(1) hold and kept TRANSACTION(2) from going on?
Could anybody share some light about this? Thanks in advanced.
------------------------
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)