Debian Codegraph @

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

raw
1 # Test that a row that ends up in a new partition contains changes made by
2 # a concurrent transaction.
3
4 setup
5 {
6 --
7 -- Setup to test concurrent handling of 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 concurrent handling of GetTupleForTrigger().
16 --
17 CREATE TABLE footrg (a int, b text) PARTITION BY LIST(a);
18 CREATE TABLE triglog as select * from footrg;
19 CREATE TABLE footrg1 PARTITION OF footrg FOR VALUES IN (1);
20 CREATE TABLE footrg2 PARTITION OF footrg FOR VALUES IN (2);
21 INSERT INTO footrg VALUES (1, 'ABC');
22 CREATE FUNCTION func_footrg() RETURNS TRIGGER AS $$
23 BEGIN
24 OLD.b = OLD.b || ' trigger';
25
26 -- This will verify that the trigger is not run *before* the row is
27 -- refetched by EvalPlanQual. The OLD row should contain the changes made
28 -- by the concurrent session.
29 INSERT INTO triglog select OLD.*;
30
31 RETURN OLD;
32 END $$ LANGUAGE PLPGSQL;
33 CREATE TRIGGER footrg_ondel BEFORE DELETE ON footrg1
34 FOR EACH ROW EXECUTE PROCEDURE func_footrg();
35
36 }
37
38 teardown
39 {
40 DROP TABLE foo;
41 DROP TRIGGER footrg_ondel ON footrg1;
42 DROP FUNCTION func_footrg();
43 DROP TABLE footrg;
44 DROP TABLE triglog;
45 }
46
47 session s1
48 step s1b { BEGIN ISOLATION LEVEL READ COMMITTED; }
49 step s1u { UPDATE foo SET a = a + 1, b = b || ' update1' WHERE b like '%ABC%'; }
50 step s1ut { UPDATE footrg SET a = a + 1, b = b || ' update1' WHERE b like '%ABC%'; }
51 step s1s { SELECT tableoid::regclass, * FROM foo ORDER BY a; }
52 step s1st { SELECT tableoid::regclass, * FROM footrg ORDER BY a; }
53 step s1stl { SELECT * FROM triglog ORDER BY a; }
54 step s1c { COMMIT; }
55
56 session s2
57 step s2b { BEGIN ISOLATION LEVEL READ COMMITTED; }
58 step s2u1 { UPDATE foo SET b = b || ' update2' WHERE a = 1; }
59 step s2u2 { UPDATE foo SET b = 'EFG' WHERE a = 1; }
60 step s2ut1 { UPDATE footrg SET b = b || ' update2' WHERE a = 1; }
61 step s2ut2 { UPDATE footrg SET b = 'EFG' WHERE a = 1; }
62 step s2c { COMMIT; }
63
64
65 # Session s1 is moving a row into another partition, but is waiting for
66 # another session s2 that is updating the original row. The row that ends up
67 # in the new partition should contain the changes made by session s2.
68 permutation s1b s2b s2u1 s1u s2c s1c s1s
69
70 # Same as above, except, session s1 is waiting in GetTupleForTrigger().
71 permutation s1b s2b s2ut1 s1ut s2c s1c s1st s1stl
72
73 # Below two cases are similar to the above two; except that the session s1
74 # fails EvalPlanQual() test, so partition key update does not happen.
75 permutation s1b s2b s2u2 s1u s2c s1c s1s
76 permutation s1b s2b s2ut2 s1ut s2c s1c s1st s1stl