[prev] 72 [next]

Transaction Isolation Levels (cont)

Example of repeatable read vs serializable
  • table R(class,value) containing (1,10) (1,20) (2,100) (2,200)
  • T1: X = sum(value) where class=1; insert R(2,X); commit
  • T2: X = sum(value) where class=2; insert R(1,X); commit
  • with repeatable read, both transactions commit, giving
    • updated table: (1,10) (1,20) (2,100) (2,200) (1,300) (2,30)
  • with serial transactions, only one transaction commits
    • T1;T2 gives (1,10) (1,20) (2,100) (2,200) (2,30) (1,330)
    • T2;T1 gives (1,10) (1,20) (2,100) (2,200) (1,300) (2,330)
  • PG recognises that committing both gives serialization violation