Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use mysql Gap Lock

Shulou Source: shulou.com Published: 2022-05-31 10:54:46 09月23日 Update

In this article, the editor introduces "how to use mysql gap lock" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use mysql gap lock" can help you solve your doubts.

Interval lock, locking only one index interval (open interval, excluding double-ended endpoints)

1. Lock the gap between the index records, or before or after the index records, excluding the index records themselves.

2. Gap locks can be used to prevent phantom reads to ensure that data is not inserted between indexes.

Example

Session 1:start transaction; select * from news where number=4 for update; session 2:start transaction; insert into news value (2); # (blocking) insert into news value (2); # (blocking) insert into news value (4); # (blocking) insert into news value (4); # (blocking) insert into news value (7); # (execution successful) insert into news value (9); # (execution successful) insert into news value (11) # (successful execution) so far, the article "how to use mysql Gap Lock" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it. If you want to know more about related articles, please follow the industry information channel.

Tags: Gaps indexes blocking success articles between content intervals appropriateness examples ideas data new knowledge more steps knowledge knowledge points articles details industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Shulou Tech Info Apple Docker