mysql 版本:8.0.32 隔离级别 RR
表结构如下:
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);| 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;||
经测试,加锁范围为(5, 25) 如果去掉 order by id desc, 加锁范围为(15, 20)