Debian Codegraph @

src/test/isolation/specs/partition-key-update-1.spec

raw
1 # Test that an error if thrown if the target row has been moved to a
2 # different partition by a concurrent session.
3
4 setup
5 {
6 --
7 -- Setup to test an error from ExecUpdate and ExecDelete.
8 --
9 CREATE TABLE foo (a int, b text) PARTITION BY LIST(a);
10 CREATE TABLE foo1 PARTITION OF foo FOR VALUES IN (1);
11 CREATE TABLE foo2 PARTITION OF foo FOR VALUES IN (2);
12 INSERT INTO foo VALUES (1, 'ABC');
13
14 --
15 -- Setup to test an error from GetTupleForTrigger
16 --
17 CREATE TABLE footrg (a int, b text) PARTITION BY LIST(a);
18 CREATE TABLE footrg1 PARTITION OF footrg FOR VALUES IN (1);
19 CREATE TABLE footrg2 PARTITION OF footrg FOR VALUES IN (2);
20 INSERT INTO footrg VALUES (1, 'ABC');
21 CREATE FUNCTION func_footrg_mod_a() RETURNS TRIGGER AS $$
22 BEGIN
23 NEW.a = 2; -- This is changing partition key column.
24 RETURN NEW;
25 END $$ LANGUAGE PLPGSQL;
26 CREATE TRIGGER footrg_mod_a BEFORE UPDATE ON footrg1
27 FOR EACH ROW EXECUTE PROCEDURE func_footrg_mod_a();
28
29 --
30 -- Setup to test an error from ExecLockRows
31 --
32 CREATE TABLE foo_range_parted (a int, b text) PARTITION BY RANGE(a);
33 CREATE TABLE foo_range_parted1 PARTITION OF foo_range_parted FOR VALUES FROM (1) TO (10);
34 CREATE TABLE foo_range_parted2 PARTITION OF foo_range_parted FOR VALUES FROM (10) TO (20);
35 INSERT INTO foo_range_parted VALUES(7, 'ABC');
36 CREATE UNIQUE INDEX foo_range_parted1_a_unique ON foo_range_parted1 (a);
37 CREATE TABLE bar (a int REFERENCES foo_range_parted1(a));
38 }
39
40 teardown
41 {
42 DROP TABLE foo;
43 DROP TRIGGER footrg_mod_a ON footrg1;
44 DROP FUNCTION func_footrg_mod_a();
45 DROP TABLE footrg;
46 DROP TABLE bar, foo_range_parted;
47 }
48
49 session s1
50 step s1b { BEGIN ISOLATION LEVEL READ COMMITTED; }
51 step s1u { UPDATE foo SET a=2 WHERE a=1; }
52 step s1u2 { UPDATE footrg SET b='EFG' WHERE a=1; }
53 step s1u3pc { UPDATE foo_range_parted SET a=11 WHERE a=7; }
54 step s1u3npc { UPDATE foo_range_parted SET b='XYZ' WHERE a=7; }
55 step s1c { COMMIT; }
56 step s1r { ROLLBACK; }
57
58 session s2
59 step s2b { BEGIN ISOLATION LEVEL READ COMMITTED; }
60 step s2u { UPDATE foo SET b='EFG' WHERE a=1; }
61 step s2u2 { UPDATE footrg SET b='XYZ' WHERE a=1; }
62 step s2i { INSERT INTO bar VALUES(7); }
63 step s2d { DELETE FROM foo WHERE a=1; }
64 step s2c { COMMIT; }
65
66 # Concurrency error from ExecUpdate and ExecDelete.
67 permutation s1b s2b s1u s1c s2d s2c
68 permutation s1b s2b s1u s2d s1c s2c
69 permutation s1b s2b s1u s2u s1c s2c
70 permutation s1b s2b s2d s1u s2c s1c
71
72 # Concurrency error from GetTupleForTrigger
73 permutation s1b s2b s1u2 s1c s2u2 s2c
74 permutation s1b s2b s1u2 s2u2 s1c s2c
75 permutation s1b s2b s2u2 s1u2 s2c s1c
76
77 # Concurrency error from ExecLockRows
78 # test waiting for moved row itself
79 permutation s1b s2b s1u3pc s2i s1c s2c
80 permutation s1b s2b s1u3pc s2i s1r s2c
81 # test waiting for in-partition update, followed by cross-partition move
82 permutation s1b s2b s1u3npc s1u3pc s2i s1c s2c
83 permutation s1b s2b s1u3npc s1u3pc s2i s1r s2c
84 # test waiting for in-partition update, followed by cross-partition move
85 permutation s1b s2b s1u3npc s1u3pc s1u3pc s2i s1c s2c
86 permutation s1b s2b s1u3npc s1u3pc s1u3pc s2i s1r s2c