MySql 中的 Next-key lock 怎么工作的?

2016-07-13 23:59:15 +08:00
 Weixiao0725

先帖一段官方的解释: A next-key lock on an index record also affects the “ gap ” before that index record. That is, a next-key lock is an index-record lock plus a gap lock on the gap preceding the index record. If one session has a shared or exclusive lock on record R in an index, another session cannot insert a new index record in the gap immediately before R in the index order.

假设我有一张表有一些数据 1,3,5,8,11 且具有非唯一索引,并且在 repeatable read 级别下执行:

select * from table where col = 8 for update;

此时会锁住 8 这条记录,另外的 gap 会锁住哪个范围?实际测试其实会锁住(5,8) 和 (8,11)这两个 gap 。但是根据官方手册里,不是before, preceding the index record 吗?( 8 , 11 )这个 gap 哪来的啊?已经纠结很久这个问题了,希望哪位大神帮忙解答下,不胜感激啊 :D

2774 次点击
所在节点    MySQL
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/292339

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX