可以在先前提交的其他事务之前提交和序列化事务吗?

时间:2018-06-07 15:46:29

标签: postgresql transactions

在这个维基百科page中可以读到:

In the other strategy, as used in multiversion concurrency control, 
Transaction 2 is permitted to commit first, which provides for better 
concurrency. However, Transaction 1, which commenced prior to Transaction 2, 
must continue to operate on a past version of the database — a snapshot of the 
moment it was started. When Transaction 1 eventually tries to commit, the DBMS 
checks if the result of committing Transaction 1 would be equivalent to the 
schedule **T1, T2**. If it is, then Transaction 1 can proceed. If it cannot be 
seen to be equivalent, however, Transaction 1 must roll back with a 
serialization failure.

最后的时间表不应该是T2,T1而不是 T1,T2

我问这个是因为如果在T1之前已经提交了T2,那么其效果已经对其他事务可见了,但T1的那些并不是因为T1还没有提交。如果T1曾经提交过,可能会出现在T2和其他同时进行的交易之前,这似乎很奇怪 - 这就像过去的写作一样。

但是,如果我错了,也就是说,如果一旦进行的交易有可能突然出现在先前已经提交的其他人之前,我希望有人能够解释原因,如果可能的话,举个实例。

由于

2 个答案:

答案 0 :(得分:1)

这可能是一种复杂的说法,如果T1在 T1启动后尝试更新由T2 修改的行,T1将收到序列化错误。

T1,T2的顺序意味着T2的结果占优势。 T1覆盖T2的结果会违反,因此T1被中止。

答案 1 :(得分:0)

为了确定两个事务之间的可串行性,只需要它们的读写之间的依赖关系,而不是它们的提交,也不需要它们的中止(显然对于中止)。

因此,在示例中,如果T1在T2之前启动,并且T2已经提交但尚未提交T1,那么它们的时间表是可序列化的,即T1可以提交,如果它等于“T1”中的任何一个T2“或”T2然后T1“。首先承诺的并不重要。

所以维基百科页面是正确的:实际的时间表必须等于串行时间表“T1然后T2”,因为T1在T2写入之前读取了该值。