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

2020-07-05 13:14:19 +08:00
 JasonLaw

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

748 次点击
所在节点    数据库
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/687284

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX