Debian Codegraph @

src/test/isolation/specs/matview-write-skew.spec

raw
1 # Test write skew with a materialized view.
2 #
3 # This test uses two serializable transactions: one that refreshes a
4 # materialized view containing a summary of some order information, and
5 # one that looks at the materialized view while doing writes on its
6 # parent relation.
7 #
8 # Any overlap between the transactions should cause a serialization failure.
9
10 setup
11 {
12 CREATE TABLE orders (date date, item text, num int);
13 INSERT INTO orders VALUES ('2022-04-01', 'apple', 10), ('2022-04-01', 'banana', 20);
14
15 CREATE MATERIALIZED VIEW order_summary AS
16 SELECT date, item, sum(num) FROM orders GROUP BY date, item;
17 CREATE UNIQUE INDEX ON order_summary(date, item);
18 -- Create a diff between the summary table and the parent orders.
19 INSERT INTO orders VALUES ('2022-04-02', 'apple', 20);
20 }
21
22 teardown
23 {
24 DROP MATERIALIZED VIEW order_summary;
25 DROP TABLE orders;
26 }
27
28 session s1
29 step s1_begin { BEGIN ISOLATION LEVEL SERIALIZABLE; }
30 step s1_refresh { REFRESH MATERIALIZED VIEW CONCURRENTLY order_summary; }
31 step s1_commit { COMMIT; }
32
33 session s2
34 step s2_begin { BEGIN ISOLATION LEVEL SERIALIZABLE; }
35 step s2_read { SELECT max(date) FROM order_summary; }
36 step s2_insert { INSERT INTO orders VALUES ('2022-04-02', 'orange', 15); }
37 step s2_update { UPDATE orders SET num = num + 1; }
38 step s2_commit { COMMIT; }
39
40 # refresh -> read -> write
41 permutation "s1_begin" "s2_begin" "s1_refresh" "s2_read" "s2_insert" "s1_commit" "s2_commit"
42 permutation "s1_begin" "s2_begin" "s1_refresh" "s2_read" "s2_update" "s1_commit" "s2_commit"
43 # read -> refresh -> write
44 permutation "s1_begin" "s2_begin" "s2_read" "s1_refresh" "s2_insert" "s1_commit" "s2_commit"
45 permutation "s1_begin" "s2_begin" "s2_read" "s1_refresh" "s2_update" "s1_commit" "s2_commit"
46 # read -> write -> refresh
47 permutation "s1_begin" "s2_begin" "s2_read" "s2_insert" "s1_refresh" "s1_commit" "s2_commit"
48 permutation "s1_begin" "s2_begin" "s2_read" "s2_update" "s1_refresh" "s1_commit" "s2_commit"
49 # refresh -> write -> read
50 permutation "s1_begin" "s2_begin" "s1_refresh" "s2_insert" "s2_read" "s1_commit" "s2_commit"
51 permutation "s1_begin" "s2_begin" "s1_refresh" "s2_update" "s2_read" "s1_commit" "s2_commit"