Debian Codegraph @

src/test/isolation/specs/insert-conflict-do-update.spec

raw
1 # INSERT...ON CONFLICT DO UPDATE test
2 #
3 # This test tries to expose problems with the interaction between concurrent
4 # sessions.
5
6 setup
7 {
8 CREATE TABLE upsert (key int primary key, val text);
9 }
10
11 teardown
12 {
13 DROP TABLE upsert;
14 }
15
16 session s1
17 setup
18 {
19 BEGIN ISOLATION LEVEL READ COMMITTED;
20 }
21 step insert1 { INSERT INTO upsert(key, val) VALUES(1, 'insert1') ON CONFLICT (key) DO UPDATE set val = upsert.val || ' updated by insert1'; }
22 step c1 { COMMIT; }
23 step a1 { ABORT; }
24
25 session s2
26 setup
27 {
28 BEGIN ISOLATION LEVEL READ COMMITTED;
29 }
30 step insert2 { INSERT INTO upsert(key, val) VALUES(1, 'insert2') ON CONFLICT (key) DO UPDATE set val = upsert.val || ' updated by insert2'; }
31 step select2 { SELECT * FROM upsert; }
32 step c2 { COMMIT; }
33
34 # One session (session 2) block-waits on another (session 1) to determine if it
35 # should proceed with an insert or update. Notably, this entails updating a
36 # tuple while there is no version of that tuple visible to the updating
37 # session's snapshot. This is permitted only in READ COMMITTED mode.
38 permutation insert1 insert2 c1 select2 c2
39 permutation insert1 insert2 a1 select2 c2