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

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

  •  
  •   yuanix · 299 天前 · 410 次点击
    这是一个创建于 299 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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   ·   我们的愿景   ·   实用小工具   ·   3009 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 13:43 · PVG 21:43 · LAX 06:43 · JFK 09:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.