| 1 |
# INSERT...ON CONFLICT DO UPDATE test with partitioned table |
| 2 |
# |
| 3 |
# We use SELECT FOR UPDATE to block the INSERT at the point where |
| 4 |
# it has found an existing tuple and is attempting to update it. |
| 5 |
# Then we can execute a conflicting update and verify the results. |
| 6 |
# Of course, this only works in READ COMMITTED mode, else we'd get an error. |
| 7 |
|
| 8 |
setup |
| 9 |
{ |
| 10 |
CREATE TABLE upsert (i int PRIMARY KEY, j int, k int) PARTITION BY RANGE (i); |
| 11 |
CREATE TABLE upsert_1 PARTITION OF upsert FOR VALUES FROM (1) TO (100); |
| 12 |
CREATE TABLE upsert_2 PARTITION OF upsert FOR VALUES FROM (100) TO (200); |
| 13 |
|
| 14 |
INSERT INTO upsert VALUES (1, 10, 100); |
| 15 |
} |
| 16 |
|
| 17 |
teardown |
| 18 |
{ |
| 19 |
DROP TABLE upsert; |
| 20 |
} |
| 21 |
|
| 22 |
session s1 |
| 23 |
setup { BEGIN ISOLATION LEVEL READ COMMITTED; } |
| 24 |
step insert1 { INSERT INTO upsert VALUES (1, 11, 111) |
| 25 |
ON CONFLICT (i) DO UPDATE SET k = EXCLUDED.k; } |
| 26 |
step select1 { SELECT * FROM upsert ORDER BY i; } |
| 27 |
step c1 { COMMIT; } |
| 28 |
|
| 29 |
session s2 |
| 30 |
setup { BEGIN ISOLATION LEVEL READ COMMITTED; } |
| 31 |
step lock2 { SELECT * FROM upsert WHERE i = 1 FOR UPDATE; } |
| 32 |
step update2a { UPDATE upsert SET i = i + 10 WHERE i = 1; } |
| 33 |
step update2b { UPDATE upsert SET i = i + 150 WHERE i = 1; } |
| 34 |
step delete2 { DELETE FROM upsert WHERE i = 1; } |
| 35 |
step c2 { COMMIT; } |
| 36 |
|
| 37 |
# Test case where concurrent update moves the target row within the partition |
| 38 |
permutation lock2 insert1 update2a c2 select1 c1 |
| 39 |
# Test case where concurrent update moves the target row to another partition |
| 40 |
permutation lock2 insert1 update2b c2 select1 c1 |
| 41 |
# Test case where target row is concurrently deleted |
| 42 |
permutation lock2 insert1 delete2 c2 select1 c1 |