【事务】可重复读

【实验】

session1
BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ;

select count(1) from t1;

session2

insert into t1(id) values(1);

结果:session1读不到session2已经提交的数据

【原理】

tuple.xmin>=snapshot.xmax,就不可见

HeapTupleSatisfiesMVCC

  XidInMVCCSnapshot(HeapTupleHeaderGetRawXmin(tuple), snapshot)==true   

      if (TransactionIdFollowsOrEquals(xid, snapshot->xmax))
        #两个相同,返回true

  #return false

posted @ 2022-02-12 23:26  stupidstan2019  阅读(22)  评论(0编辑  收藏  举报