Bug #1866 | Attempting to insert into a gap you hold a row lock on can deadlock | ||
---|---|---|---|
Submitted: | 17 Nov 2003 20:22 | Modified: | 18 Nov 2003 5:14 |
Reporter: | Will Bryant | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 4.0.16 | OS: | Linux (Linux) |
Assigned to: | CPU Architecture: | Any |
[17 Nov 2003 20:22]
Will Bryant
[18 Nov 2003 5:14]
Heikki Tuuri
Hi! The problem is that an index cursor in InnoDB never reverses if it needs to wait for a lock. Suppose we have index records "AA" "AC", T1 has a next-key lock on "AC", and T2 is waiting for a next-key lock on "AC". Can T1 insert "AB" to the gap between "AA" and "AC"? No, because the index cursor of T1 has already passed that position and is waiting on "AC". If T1 is doing a SELECT which should see "AB", then allowing T2 to insert would cause nonserializable execution. Since purge can remove index records, it can happen that 2 transactions have a GRANTED lock on the same gap. That is why I have chosen in InnoDB that a lock on a gap only has an inhibitive action: it can prevent an insert by another trx, but it does not give a transaction a right to insert. We could optimize this by letting T1 to reverse its cursor and temporarily release the waiting lock request on "AC", if T2 wants to insert to the gap. But it is not easy to make a correct algorithm. Best regards, Heikki
[18 Nov 2003 5:16]
Heikki Tuuri
Correct the typo: Can T1 insert "AB" to the gap between "AA" and "AC"? No, because the index cursor of T2... Regards, Heikki