| 1 |
# Read-write-unique test. |
| 2 |
|
| 3 |
setup |
| 4 |
{ |
| 5 |
CREATE TABLE test (i integer PRIMARY KEY); |
| 6 |
} |
| 7 |
|
| 8 |
teardown |
| 9 |
{ |
| 10 |
DROP TABLE test; |
| 11 |
} |
| 12 |
|
| 13 |
session s1 |
| 14 |
setup { BEGIN ISOLATION LEVEL SERIALIZABLE; } |
| 15 |
step r1 { SELECT * FROM test WHERE i = 42; } |
| 16 |
step w1 { INSERT INTO test VALUES (42); } |
| 17 |
step c1 { COMMIT; } |
| 18 |
|
| 19 |
session s2 |
| 20 |
setup { BEGIN ISOLATION LEVEL SERIALIZABLE; } |
| 21 |
step r2 { SELECT * FROM test WHERE i = 42; } |
| 22 |
step w2 { INSERT INTO test VALUES (42); } |
| 23 |
step c2 { COMMIT; } |
| 24 |
|
| 25 |
# Two SSI transactions see that there is no row with value 42 |
| 26 |
# in the table, then try to insert that value; T1 inserts, |
| 27 |
# and then T2 blocks waiting for T1 to commit. Finally, |
| 28 |
# T2 reports a serialization failure. |
| 29 |
|
| 30 |
permutation r1 r2 w1 w2 c1 c2 |
| 31 |
|
| 32 |
# If the value is already visible before T2 begins, then a |
| 33 |
# regular unique constraint violation should still be raised |
| 34 |
# by T2. |
| 35 |
|
| 36 |
permutation r1 w1 c1 r2 w2 c2 |