创建两个表以进行比较:
create table t1(id integer primary key);
create table t2(id integer primary key, num integer);
insert into t1 values (0),(3),(6),(9);
insert into t2 values (0, 0), (3, 3), (6, 6), (9, 9);
启动事务tx1
并对表t1
执行锁定读取:
start transaction;
select * from t1 where id >=3 and id < 8 for update;
tx1
持有的锁如下所示:
现在回滚tx1
,启动事务tx2
并对表t2
执行锁定读取:
start transaction;
select * from t2 where id >=3 and id < 8 for update;
tx2
持有的锁如下所示:
tx2
的行为符合我对MySQL锁定模型的理解.为什么tx1
锁定表t1
中的每条索引记录?
="=引用=外部链接=
现在使用解释,我看到了一些不同之处: