表结构如下:
create table t
(
id int not null
primary key,
c int null,
d int null
);
create index c
on t (c);
insert into t values(0,0,0),(5,5,5),(10,10,10),(15,15,15),(20,20,20),(25,25,25);
mysql 版本:8.0.32 隔离级别 RR
| session A | session B |
|---|---|
| begin; | |
| select * from t where id>=15 and id<=20 order by id desc for update ; | |
| insert into t values (22,22,22); //会被阻塞 | |
| commit; |
请问,id 是主键,为什么 session B 会进入锁等待?按理说唯一索引不会检查区间(20, 25)吧