Why is the Next-key lock of Innodb left open and right closed?

reference article: Innodb lock mechanism: Next-Key Lock talk about-jyzhou-blog Park

Why should Next-Key Lock be designed as a left open and right closed interval? Can"t be designed as a gap lock? Why is right closed?

ask the boss to answer.

< H1 > add: < / H1 >

clipboard.png

BEGIN;
SELECT * FROM a WHERE id=3 FOR UPDATE; -sharp 
UPDATE a SET id=2 WHERE id=3 -sharpid
UPDATE a SET id=5 WHERE id=3 -sharp

SELECT * FROM a WHERE id=6 FOR UPDATE; -sharp 66
UPDATE a SET id=6 WHERE id=6 -sharp 66

Why are boundaries treated differently?


next-key lock is a logical name. In fact, it is a gap lock plus a row lock, and your right lock is the first question of row lock
-update
, because at the RR level, the basic unit of locking is next-key lock (under certain conditions it will be reduced to a row lock or gap lock, such as an equivalent query for a unique index), so 6 will be locked, although logically it is not necessary.
and the other part of you, are there any comments that are wrong and don't understand


about the gap lock: if Chengdu is designed to be a gap lock, then these records will not be locked for id = 1meme 3jort 6jin15 these records, will they? Of course it won't work. I don't quite understand the following
.

Menu