0

In mysql, as per the official doc and other documentations,

When the IsolationLevel = ReadUncommitted or ReadCommitted or RepeatableRead, it uses Optimistic CC (with MVCC) which usually doesn't takes much locks. In case of Serializable, we will see all forms of locks like Read, Write, Range, Gap etc...

But I recently faced a problem in Hibernate when isolationLevel = RepeatableRead, it threw LockAquisitionException. After hours of debugging and analysing the behaviours, I found that we are inserting new rows which references the parent record (PrimaryKey) where INNODB locks the parent record (and) another transaction tried to update the parent record and threw LockAquisitionException (after some timeout).

After some googling, I came to know that, mysql takes locks in certain corner cases if the isolation level < Serializable which I couldn't find even after spending lot more time and documentations details about lot more variations and it's hard to spin all these around the head.

Can someone provide details on what locks, mysql takes automatically irrespective of isolation level in simple terms. This will help to identify the anamolies in the code and correct it.

In my case, no queries will be executed with "for update" or "lock in share mode". I'm concerned about only plain sql queries without any intention locks.

Manikandan Kbk
  • 131
  • 1
  • 8
  • The [MySQL documentation](https://dev.mysql.com/doc/refman/8.0/en/innodb-locks-set.html) provides a list of which locks are taken in which situations (including the locks on foreign keys), which seems to be what you are asking about. If you found corner cases that are not covered and/or which you need help with to figure out, you should mention them specifically (for example tables and queries that give you a lock that you don't expect). – Solarflare Jul 28 '21 at 18:21
  • 1
    Please provide the SQL for a use case. – Rick James Jul 31 '21 at 19:27

0 Answers0