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 · Jul 13, 2016 · 3450 views
    This topic created in 3620 days ago, the information mentioned may be changed or developed.

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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5263 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 08:00 · PVG 16:00 · LAX 01:00 · JFK 04:00
    ♥ Do have faith in what you're doing.