Home > Database > Mysql Tutorial > How to use mysql gap lock

How to use mysql gap lock

WBOY
Release: 2023-05-29 10:31:05
forward
1378 people have browsed it

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

1. Lock in the gap between index records, or lock before or after the index record, The index record itself is not included.

2. Gap locks can be used to prevent phantom reads to ensure that data will not be 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,4);#(阻塞)
insert into news value(2,2);#(阻塞)
insert into news value(4,4);#(阻塞)
insert into news value(4,5);#(阻塞)
insert into news value(7,5);#(执行成功)
insert into news value(9,5);#(执行成功)
insert into news value(11,5);#(执行成功)
Copy after login

The above is the detailed content of How to use mysql gap lock. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template