yuanix
V2EX  ›  问与答

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

  •  
  •   yuanix · Jul 3, 2023 · 810 views
    This topic created in 1045 days ago, the information mentioned may be changed or developed.

    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; 仍然能执行?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5512 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 05:47 · PVG 13:47 · LAX 22:47 · JFK 01:47
    ♥ Do have faith in what you're doing.