理论上说,一组并发事务是可串行化的当且仅当它们的并发执行等同于它们可能的串行执行之一。
现在事务T1和T2的并发执行是可序列化的,因为它等同于串行执行"T1然后T2“
T1: r1x w1y c1
T2: w2x c2
(i.e., T1 reads x, T2 writes x, T1 writes y, T2 commits, and finally, T1 commits)但是,在PostgreSQL 10.4中尝试时,如下所示:
T1: begin
T1: set transaction isolation level serializable;
T2: begin
T2: set transaction isolation level serializable;
T2: update variables set value = value + 1 where name = 'x'
T1: update variables set value = value + 1 where name = 'y'
T2: commit
T1: commit当此事务试图提交时,数据库将中止T1。为什么?
发布于 2018-06-12 05:26:14
PostgreSQL使用启发式方法来确定是否中止可序列化的事务,因为这太难准确了。因此,即使存在等效的串行执行(假阳性),事务也可能被中止。
但我怀疑这个案子有不同的原因。如果您查看执行计划,您可能会看到顺序扫描。现在,顺序扫描读取所有行,因此T2在其更新过程中读取了y。
可序列化事务的行为取决于所选的执行计划!
https://stackoverflow.com/questions/50807118
复制相似问题