[MDEV-16675] Unnecessary explicit lock acquisition during UPDATE or DELETE Created: 2018-07-03 Updated: 2021-07-21 Resolved: 2018-07-04 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Storage Engine - InnoDB |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3 |
| Fix Version/s: | 10.3.9 |
| Type: | Bug | Priority: | Major |
| Reporter: | Marko Mäkelä | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | lock, performance | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Description |
|
In InnoDB, an INSERT will not create an explicit lock object. Instead, the inserted record is initially implicitly locked by the transaction that wrote its trx_t::id to the hidden system column DB_TRX_ID. (Other transactions would check if DB_TRX_ID is referring to a transaction that has not been committed.) If a record was inserted in the current transaction, it would be implicitly locked by that transaction. Only if some other transaction is requesting access to the record, the implicit lock should be converted to an explicit one, so that the waits-for graph can be constructed for detecting deadlocks and lock wait timeouts. The bug is that currently, InnoDB would convert the implicit lock to an explicit one, even if no conflict exists. Here is an example:
In this test, there is no conflict, and the DELETE statement should not convert the implicit lock into an explicit one. But, the function lock_rec_convert_impl_to_expl_for_trx() is being invoked during the test. |
| Comments |
| Comment by Marko Mäkelä [ 2018-07-03 ] |
|
This fix should reduce the amount of transactions aborted due to deadlocks. I had to adjust the test main.xa so that it would continue to generate a deadlock error, instead of getting a report of a lock wait timeout. I remember reports about deadlocks in INSERT…ON DUPLICATE KEY UPDATE in MySQL. I believe that this fix together with the already implemented |
| Comment by Thirunarayanan Balathandayuthapani [ 2018-07-04 ] |
|
Patch looks good to me. |