MySQL Forums
Forum List  »  InnoDB

Need help for understanding why the MySQL allow to gap lock conflicting between two transactions.
Posted by: hanjae jung
Date: July 26, 2021 07:15PM

Hi, I'm a developer engineering multiple servers.

Multiples servers try the next queries simultaneously.

"SELECT * FROM xxx WHERE txid = 3" FOR UPDATE;

(If it doesn't have any records, try the next)
"INSERT INTO xxx (..., txid, ...) VALUES (..., 3, ...)

There are unique constraints on txid.


When two transactions (by two servers) excute "SELECT * FOR UPDATE", they get gap lock independently, but If the one tried to "INSERT", get blocked.

So, I read the manual and found that "It is also worth noting here that conflicting locks can be held on a gap by different transactions." and "The reason conflicting gap locks are allowed is that if a record is purged from an index, the gap locks held on the record by different transactions must be merged.


I figured out why the transaction gets blocking, but still, am curious why Mysql allows conflicting gap locks? I don't understand the "merged". Can I get an explanation with an example? Thanks in advance (_ _).

Options: ReplyQuote


Subject
Views
Written By
Posted
Need help for understanding why the MySQL allow to gap lock conflicting between two transactions.
164
July 26, 2021 07:15PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.