多くの InnoDB ロック命令がありますが、私のテストでは、まだ混乱しているものがあります。MySQL のバージョンは 5.7 で、Repeatable Read 分離レベルを備えています。
drop table if exists t1;
create table if not exists t1(id float,name varchar(20),key idx_id(id));
insert into t1 values (1,'a'),(3,'c'), (4,'d'), (10,'f');
-- session1:
START TRANSACTION;
insert into t1 values (5,'a');
-- session 2:
update t1 set name='a2' where id > 4 and id < 5; -- wating for lock
-- session3:
update t1 set name='a2' where id > 5 and id < 10; -- no wait,executed.
私の理解では、セッション 1 は挿入インテンション ロック (4,10) を保持し、セッション 2 は X ロック (4,5) を待機しているため、セッション 1 によってブロックされます。セッション 3 はセッション 1 がロックを解放するのを待つことができますが、実際にはセッション 3 が実行されるだけです。これはどのように起こったのですか?