Debian Codegraph @

src/test/isolation/specs/detach-partition-concurrently-1.spec

raw
1 # Test that detach partition concurrently makes the partition invisible at the
2 # correct time.
3
4 setup
5 {
6 DROP TABLE IF EXISTS d_listp, d_listp1, d_listp2;
7 CREATE TABLE d_listp (a int) PARTITION BY LIST(a);
8 CREATE TABLE d_listp1 PARTITION OF d_listp FOR VALUES IN (1);
9 CREATE TABLE d_listp2 PARTITION OF d_listp FOR VALUES IN (2);
10 INSERT INTO d_listp VALUES (1),(2);
11 }
12
13 teardown {
14 DROP TABLE IF EXISTS d_listp, d_listp2, d_listp_foobar;
15 }
16
17 session s1
18 step s1b { BEGIN; }
19 step s1brr { BEGIN ISOLATION LEVEL REPEATABLE READ; }
20 step s1s { SELECT * FROM d_listp; }
21 step s1ins { INSERT INTO d_listp VALUES (1); }
22 step s1ins2 { INSERT INTO d_listp VALUES (2); }
23 step s1prep { PREPARE f(int) AS INSERT INTO d_listp VALUES ($1); }
24 step s1prep1 { PREPARE f(int) AS INSERT INTO d_listp VALUES (1); }
25 step s1prep2 { PREPARE f(int) AS INSERT INTO d_listp VALUES (2); }
26 step s1exec1 { EXECUTE f(1); }
27 step s1exec2 { EXECUTE f(2); }
28 step s1dealloc { DEALLOCATE f; }
29 step s1c { COMMIT; }
30
31 session s2
32 step s2detach { ALTER TABLE d_listp DETACH PARTITION d_listp2 CONCURRENTLY; }
33 step s2drop { DROP TABLE d_listp2; }
34
35 session s3
36 step s3s { SELECT * FROM d_listp; }
37 step s3i { SELECT relpartbound IS NULL FROM pg_class where relname = 'd_listp2'; }
38 step s3ins2 { INSERT INTO d_listp VALUES (2); }
39
40 # The transaction that detaches hangs until it sees any older transaction
41 # terminate, as does anybody else.
42 permutation s1b s1s s2detach s1s s1c s1s
43
44 # relpartbound remains set until s1 commits
45 # XXX this could be timing dependent :-(
46 permutation s1b s1s s2detach s1s s3s s3i s1c s3i s2drop s1s
47
48 # In read-committed mode, the partition disappears from view of concurrent
49 # transactions immediately. But if a write lock is held, then the detach
50 # has to wait.
51 permutation s1b s1s s2detach s1ins s1s s1c
52 permutation s1b s1s s1ins2 s2detach s1ins s1s s1c
53
54 # In repeatable-read mode, the partition remains visible until commit even
55 # if the to-be-detached partition is not locked for write.
56 permutation s1brr s1s s2detach s1ins s1s s1c
57 permutation s1brr s1s s2detach s1s s1c
58
59 # Another process trying to acquire a write lock will be blocked behind the
60 # detacher
61 permutation s1b s1ins2 s2detach s3ins2 s1c
62
63 # a prepared query is not blocked
64 permutation s1brr s1prep s1s s2detach s1s s1exec1 s3s s1dealloc s1c
65 permutation s1brr s1prep s1exec2 s2detach s1s s1exec2 s3s s1c s1dealloc
66 permutation s1brr s1prep s1s s2detach s1s s1exec2 s1c s1dealloc
67 permutation s1brr s1prep s2detach s1s s1exec2 s1c s1dealloc
68 permutation s1brr s1prep1 s2detach s1s s1exec2 s1c s1dealloc
69 permutation s1brr s1prep2 s2detach s1s s1exec2 s1c s1dealloc