在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”,是我理解错了文档中的那句话?还是文档的一个错误?