【发布时间】:2022-01-19 06:31:59
【问题描述】:
准备好了
# ready
CREATE TABLE table_a
(
id int PRIMARY KEY AUTO_INCREMENT,
col_1 INT,
INDEX idx_a (col_1)
) ENGINE = innodb;
| id | col_a |
|---|---|
| 1 | 10 |
| 2 | 15 |
| 3 | 20 |
| 4 | 25 |
交易 1
START TRANSACTION;
SELECT *
FROM table_a
WHERE col_1 = 15
FOR UPDATE;
交易 2
START TRANSACTION;
# LOCK
INSERT INTO table_a (col_1) VALUES (10);
performance_schema.data_locks;
| LOCK_TYPE | LOCK_MODE | LOCK_STATUS | LOCK_DATA |
|---|---|---|---|
| TABLE | IX | GRANTED | |
| RECORD | X | GRANTED | 15, 2 |
| RECORD | X,REC_NOT_GAP | GRANTED | 2 |
| RECORD | X,GAP | GRANTED | 20, 3 |
我想知道为什么 Transaction2 被锁定
LOCK_MODE=x,LOCK_DATA=15,2不是在11-14范围内吗?
【问题讨论】:
-
如果将
col_1 = 15更改为col_1 = 20会发生什么?