V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JasonLaw
V2EX  ›  数据库

MySQL 文档关于插入意向锁的一个错误?

  •  
  •   JasonLaw · 2020-07-05 13:14:19 +08:00 · 753 次点击
    这是一个创建于 1602 天前的主题,其中的信息可能已经有所发展或是发生改变。

    MySQL :: MySQL 8.0 Reference Manual :: 15.7.1 InnoDB Locking - Insert Intention Locks中,有一个示例:

    Client A creates a table containing two index records (90 and 102) and then starts a transaction that places an exclusive lock on index records with an ID greater than 100. The exclusive lock includes a gap lock before record 102:
    
    mysql> CREATE TABLE child (id int(11) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
    mysql> INSERT INTO child (id) values (90),(102);
    
    mysql> START TRANSACTION;
    mysql> SELECT * FROM child WHERE id > 100 FOR UPDATE;
    +-----+
    | id  |
    +-----+
    | 102 |
    +-----+
    
    Client B begins a transaction to insert a record into the gap. The transaction takes an insert intention lock while it waits to obtain an exclusive lock.
    
    mysql> START TRANSACTION;
    mysql> INSERT INTO child (id) VALUES (101);
    

    它说“The transaction takes an insert intention lock while it waits to obtain an exclusive lock”,但是我自己执行后,select * from performance_schema.data_locks的输出如下:

    +--------+---------------------------------------+-----------------------+-----------+----------+---------------+-------------+----------------+-------------------+------------+-----------------------+-----------+------------------------+-------------+------------------------+
    | ENGINE | ENGINE_LOCK_ID                        | ENGINE_TRANSACTION_ID | THREAD_ID | EVENT_ID | OBJECT_SCHEMA | OBJECT_NAME | PARTITION_NAME | SUBPARTITION_NAME | INDEX_NAME | OBJECT_INSTANCE_BEGIN | LOCK_TYPE | LOCK_MODE              | LOCK_STATUS | LOCK_DATA              |
    +--------+---------------------------------------+-----------------------+-----------+----------+---------------+-------------+----------------+-------------------+------------+-----------------------+-----------+------------------------+-------------+------------------------+
    | INNODB | 140043377180872:1066:140043381460688  |                  2166 |        49 |       90 | test          | child       | NULL           | NULL              | NULL       |       140043381460688 | TABLE     | IX                     | GRANTED     | NULL                   |
    | INNODB | 140043377180872:5:4:3:140043381457776 |                  2166 |        49 |       90 | test          | child       | NULL           | NULL              | PRIMARY    |       140043381457776 | RECORD    | X,GAP,INSERT_INTENTION | WAITING     | 102                    |
    | INNODB | 140043377180024:1066:140043381454544  |                  2165 |        48 |      133 | test          | child       | NULL           | NULL              | NULL       |       140043381454544 | TABLE     | IX                     | GRANTED     | NULL                   |
    | INNODB | 140043377180024:5:4:1:140043381451552 |                  2165 |        48 |      133 | test          | child       | NULL           | NULL              | PRIMARY    |       140043381451552 | RECORD    | X                      | GRANTED     | supremum pseudo-record |
    | INNODB | 140043377180024:5:4:3:140043381451552 |                  2165 |        48 |      133 | test          | child       | NULL           | NULL              | PRIMARY    |       140043381451552 | RECORD    | X                      | GRANTED     | 102                    |
    +--------+---------------------------------------+-----------------------+-----------+----------+---------------+-------------+----------------+-------------------+------------+-----------------------+-----------+------------------------+-------------+------------------------+
    

    Client B 对应的那个事务正在等待获取插入意向锁,并不是文档所说的“takes an insert intention lock while it waits to obtain an exclusive lock”,是我理解错了文档中的那句话?还是文档的一个错误?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   951 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:54 · PVG 06:54 · LAX 14:54 · JFK 17:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.