MySQL5.7.11,tx_isolation 是 REPEATABLE-READ;
像这样的表:
CREATE TABLE a (
id int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
insert into a values(1);
在 session1 中,执行如下:
begin;
select * from a where id=2 for update;
然后在 session2 中,执行:
begin;
insert into a values(3);
session2被阻塞了,我认为session2被阻塞是因为GAP锁,但是在information_schema.innodb_lock中,显示了supremum pseudo-record和RECORD Lock;
*************************** 1. row ***************************
lock_id: 234076:115:3:1
lock_trx_id: 234076
lock_mode: X
lock_type: RECORD
lock_table: `test`.`a`
lock_index: PRIMARY
lock_space: 115
lock_page: 3
lock_rec: 1
lock_data: supremum pseudo-record
*************************** 2. row ***************************
lock_id: 234075:115:3:1
lock_trx_id: 234075
lock_mode: X
lock_type: RECORD
lock_table: `test`.`a`
lock_index: PRIMARY
lock_space: 115
lock_page: 3
lock_rec: 1
lock_data: supremum pseudo-record
2 rows in set (0.00 sec)
MySQL_Doc 描述如下:
For the last interval, the next-key lock locks the gap above the largest value in the index and the
“supremum” pseudo-record having a value higher than any value actually in the index. The supremum
is not a real index record, so, in effect, this next-key lock locks only the gap following the largest index
value.
为什么 Record Lock 和 lock_data 是 supremum 伪记录?