0

Over the weekend one of my clients switched from MyISAM to InnoDB and the very first day they got deadlocks errors in the php logs. This is the engine status of MySQL:

    ------------------------
    LATEST DETECTED DEADLOCK
    ------------------------
    140616 17:54:23
    *** (1) TRANSACTION:
    TRANSACTION AA7939, ACTIVE 0 sec fetching rows
    mysql tables in use 1, locked 1
    LOCK WAIT 6 lock struct(s), heap size 1248, 8 row lock(s), undo log entries 3
    MySQL thread id 45955, OS thread handle 0x7f19aea0c700, query id 6087879 {hostname} 10.132.0.18 {dbuser} Updating
    Update sid Set SID_Active = 'n' Where SID_Demandeur = '991821' AND SID_Context_Type = 'PORTAL'
    *** (1) WAITING FOR THIS LOCK TO BE GRANTED:
    RECORD LOCKS space id 3955 page no 80 n bits 168 index `PRIMARY` of table `{db_prod}`.`sid` trx id AA7939 lock_mode X locks rec but not gap waiting
    Record lock, heap no 11 PHYSICAL RECORD: n_fields 14; compact format; info bits 0
     ...

    *** (2) TRANSACTION:
    TRANSACTION AA5366, ACTIVE 708 sec fetching rows, thread declared inside InnoDB 192
    mysql tables in use 2, locked 2
    254 lock struct(s), heap size 31160, 18345 row lock(s), undo log entries 18317
    MySQL thread id 45393, OS thread handle 0x7f19ae949700, query id 6060259 {hostname} 10.132.0.18 {dbuser} Sending data
    Delete From tmp_training_session_dates Where RemoteUserId Not In (Select CONCAT(SID_Demandeur,'_',SID_Sid) From sid Where SID_Active = 'o' And SID_Dern_Maj >='1919-05-24 10:22:35')
    *** (2) HOLDS THE LOCK(S):
    RECORD LOCKS space id 3955 page no 80 n bits 168 index `PRIMARY` of table `{db_prod}`.`sid` trx id AA5366 lock mode S locks rec but not gap
    Record lock, heap no 11 PHYSICAL RECORD: n_fields 14; compact format; info bits 0

    ...

    *** (2) WAITING FOR THIS LOCK TO BE GRANTED:
    RECORD LOCKS space id 3955 page no 17 n bits 160 index `PRIMARY` of table `{db_prod}`.`sid` trx id AA5366 lock mode S locks rec but not gap waiting
    Record lock, heap no 25 PHYSICAL RECORD: n_fields 14; compact format; info bits 0

Help me understand this deadlock. How SELECT can hold the lock in this case?

1 Answer 1

1

I think you are trying to update a record or index (first transaction) that should be used by the the second transaction to perform delete.

See also MySQL deadlock documentation:

InnoDB uses automatic row-level locking. You can get deadlocks even in the case of transactions that just insert or delete a single row. That is because these operations are not really “atomic”; they automatically set locks on the (possibly several) index records of the row inserted or deleted.

If your software was worked with MyISAM you can try to commit every update/delete queries or, better, you can explicit define sid table as MyISAM:

ALTER TABLE sid ENGINE = MyISAM;
1
  • Software vendor does not want to go back to MyISAM. So haven't tried it. They set innodb_table_locks = 0 in MySQL and change the code a bit but the problem persists. Commented Jun 19, 2014 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.