V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
Weixiao0725
V2EX  ›  MySQL

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

  •  
  •   Weixiao0725 · 2016-07-13 23:59:15 +08:00 · 2767 次点击
    这是一个创建于 2836 天前的主题,其中的信息可能已经有所发展或是发生改变。

    先帖一段官方的解释: 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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2856 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 13:41 · PVG 21:41 · LAX 06:41 · JFK 09:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.