SQL Server 一致性读
- A new transaction is initiated, and it is assigned a transaction sequence number.
- 每个事务开始时被分配一个事务序列号Transaction Sequence Number(TSN)。
- The Database Engine reads a row within the transaction and retrieves the row version from tempdb whose sequence number is closest to, and lower than, the transaction sequence number.
- 读事务通过数据库引擎在tempdb中检索TSN小于当前读事务TSN的行(这些行都带有各自事务的TSN信息)。
- The Database Engine checks to see if the transaction sequence number is not in the list of transaction sequence numbers of the uncommitted transactions active when the snapshot transaction started.
- 数据库引擎检查:步骤2中找到的行的TSN是否在未提交事务列表中,此列表中的未提交事务都是读事务启动时就已经处于active状态的事务。
- The transaction reads the version of the row from tempdb that was current as of the start of the transaction. It will not see new rows inserted after the transaction was started because those sequence number values will be higher than the value of the transaction sequence number.
- 当前事务只读取:离当前读事务TSN最近,且小于当前读事务TSN的行版本。这意味只读取最新的已提交数据。
- The current transaction will see rows that were deleted after the transaction began, because there will be a row version in tempdb with a lower sequence number value.
- 当前事务永远不会读取到其他事物的未提交修改,因为在tempdb中总会存在修改行的行版本(即前镜像)。
需要考虑的一种情形是: