V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yuanix
V2EX  ›  问与答

为什么 SELECT ... FOR SHARE 没被另一个事务的 UPDATE 阻塞?

  •  
  •   yuanix · 2023 年 7 月 3 日 · 732 次点击
    这是一个创建于 1004 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Schema 如下:

    CREATE TABLE `table0` (
      `pkId` int DEFAULT NULL,
      `pkAttr0` int NOT NULL,
      `coAttr0_0` int DEFAULT NULL,
      PRIMARY KEY (`pkAttr0`),
      KEY `table0index_pk` (`pkAttr0`),
      KEY `table0index_commAttr0` (`coAttr0_0`)
    )
    
    insert into table0 values(1,1,1);
    

    操作序列:

    session1 > begin;
    session1 > update table0 set coAttr0_0=2;
    session2 > begin;
    session2 > select pkAttr0 from table0 for share; -- is not blocked
    

    session1 > update table0 set coAttr0_0=2; 已经锁定了所有行,为什么 session2 > select pkAttr0 from table0 for share; 仍然能执行?

    目前尚无回复
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   936 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 20:48 · PVG 04:48 · LAX 13:48 · JFK 16:48
    ♥ Do have faith in what you're doing.