Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of mysql gap lock

Shulou Source: shulou.com Published: 2022-06-03 10:37:41 11月15日 Update

mysql gap lock usage is what, for this problem, this article details the corresponding analysis and solution, hoping to help more want to solve this problem of small partners to find a simpler and easier way.

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

Lock in gaps between index records, or before or after index records, excluding index records themselves.

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

examples

session 1:start transaction ; select * from news where number=4 for update ; session 2:start transaction ;insert into news value(2,4);#(blocking) insert into news value(2,2);#(blocking) insert into news value(4,4);#(blocking) insert into news value (4,5);#(blocking) insert into news value(7,5);#(successful execution) insert into news value(9,5);#(successful execution) insert into news value(11,5);#(successful execution) The answer to the question about the usage of mysql gap lock is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts, you can pay attention to the industry information channel for more relevant knowledge.

Tags: Indexes gaps blocking success problems between intervals more help answers easy easy content examples guys partners data methods knowledge articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MariaDB Apple Redmi OPPO Reno