账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于next-key锁,gap锁区间的疑问
    • 纯天然无毒无添加防腐剂2018-02-27 00:00
    27
    0

    表user结构如下:

    CREATE TABLE `user` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `name` varchar(255) NOT NULL DEFAULT '',
      `score` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`),
      KEY `index_score` (`score`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    当前的user表数据如下:

    id name score
    1 test1 5
    2 test2 10
    3 test3 15
    4 test4 22

    我测试gap锁区间的sql如下:

    事务隔离级别为RR
    session 1 session 2
    begin; begin;
    update user set name = 'test' where score = 15; -
    - insert into user values(5, 'test5', 10); # 阻塞
    - insert into user values(5, 'test5', 21); # 阻塞
    commit; -
    - commit;
    Suppose that an index contains the values 10, 11, 13, and 20. The possible next-key locks for this index cover the following intervals, where a round bracket denotes exclusion of the interval endpoint and a square bracket denotes inclusion of the endpoint:

    (negative infinity, 10]
    (10, 11]
    (11, 13]
    (13, 20]
    (20, positive infinity)

    14.6.4.2 InnoDB Record, Gap, and Next-Key Locks

    按照上面的说明,gap锁的区间应该是(10, 15],(15, 22],也就是(10, 22],但是我实际测试发现gap锁区间为[10, 22)?

    环境说明:

    System: ubuntu 16.04
    Mysql Version: 5.5.56
    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 黄二两 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版