Reputation: 23
I am getting the following deadlock but inside one transaction only. How is that possible. The output of SHOW ENGINE INNODB STATUS is as below. Also whenever I am getting this deadlock I am also getting foreign key error. There are two tables one is payments and the other is master_payments. master_pid column in payments table is the foreign key for id in master_payments table
------------------------
LATEST FOREIGN KEY ERROR
------------------------
2025-02-21 09:50:42 22911642420992 Transaction:
TRANSACTION 325186431, ACTIVE 0 sec inserting
mysql tables in use 1, locked 1
5 lock struct(s), heap size 1128, 2 row lock(s), undo log entries 1
MySQL thread id 25930831, OS thread handle 22911642420992, query id 1903837014 192.168.1.120 collection_user_be update
insert into payments (collection_invoice_id, amount, payment_type,master_pid, cashier_verified_at, reference_number, due_date, bank_id, upi_unique_id, bank_statement_id, payment_verification_status) values (26586585, 49, "Cash" , 89778, null,null,null,null,null,null,null),(26586585, 1000, "UPI" , 89779, "2025-02-21 15:20:42","156560770908",null,null,null,93505702,"UpiAutoVerified")
Foreign key constraint fails for table `cdms`.`payments`:
,
CONSTRAINT `fk_master_pid` FOREIGN KEY (`master_pid`) REFERENCES `master_payments` (`id`)
Trying to add in child table, in index fk_master_pid tuple:
DATA TUPLE: 2 fields;
0: len 4; hex 80015eb2; asc ^ ;;
1: len 4; hex 80cbea52; asc R;;
But in parent table `cdms`.`master_payments`, in index PRIMARY,
the closest match we can find is record:
PHYSICAL RECORD: n_fields 17; compact format; info bits 0
0: len 4; hex 80015eb1; asc ^ ;;
1: len 6; hex 00001361f376; asc a v;;
2: len 7; hex 0200000a28241a; asc ($ ;;
3: len 1; hex 03; asc ;;
4: len 4; hex 32303033; asc 2003;;
5: len 12; hex 353431383730333530303935; asc 541870350095;;
6: len 1; hex 05; asc ;;
7: len 1; hex 05; asc ;;
8: len 4; hex 80003057; asc 0W;;
9: len 5; hex 99b5ea9ca9; asc ;;
10: len 5; hex 99b5ea9caa; asc ;;
11: SQL NULL;
12: SQL NULL;
13: len 1; hex 80; asc ;;
14: SQL NULL;
15: SQL NULL;
16: len 1; hex 80; asc ;;
------------------------
LATEST DETECTED DEADLOCK
------------------------
2025-02-21 09:50:42 22844643706624
*** (1) TRANSACTION:
TRANSACTION 325186422, ACTIVE 0 sec fetching rows
mysql tables in use 1, locked 1
LOCK WAIT 386 lock struct(s), heap size 57464, 88181 row lock(s), undo log entries 13
MySQL thread id 25930874, OS thread handle 22932963624704, query id 1903836904 192.168.1.74 collection_user_be updating
UPDATE master_payments SET curr_state = 'SETTLE', action = 'CASHIERVERIF' WHERE mode = 'UPI' AND ref_no = '541870350095'
*** (1) HOLDS THE LOCK(S):
RECORD LOCKS space id 592 page no 8 n bits 240 index PRIMARY of table `cdms`.`master_payments` trx id 325186422 lock_mode X
Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
0: len 8; hex 73757072656d756d; asc supremum;;
Record lock, heap no 2 PHYSICAL RECORD: n_fields 17; compact format; info bits 0
0: len 4; hex 80000001; asc ;;
1: len 6; hex 000011d887e4; asc ;;
2: len 7; hex 81000010830110; asc ;;
3: len 1; hex 01; asc ;;
4: len 2; hex 3230; asc 20;;
5: SQL NULL;
6: SQL NULL;
7: len 1; hex 01; asc ;;
8: SQL NULL;
9: len 5; hex 99b5132b60; asc +`;;
10: len 5; hex 99b5132b60; asc +`;;
11: SQL NULL;
12: SQL NULL;
13: len 1; hex 80; asc ;;
14: SQL NULL;
15: SQL NULL;
16: len 1; hex 80; asc ;;
Upvotes: -1
Views: 35