| 1 |
# Test that detach partition concurrently makes the partition safe |
| 2 |
# for foreign keys that reference it. |
| 3 |
|
| 4 |
setup |
| 5 |
{ |
| 6 |
DROP TABLE IF EXISTS d_lp_fk, d_lp_fk_1, d_lp_fk_2, d_lp_fk_r; |
| 7 |
|
| 8 |
CREATE TABLE d_lp_fk (a int PRIMARY KEY) PARTITION BY LIST(a); |
| 9 |
CREATE TABLE d_lp_fk_1 PARTITION OF d_lp_fk FOR VALUES IN (1); |
| 10 |
CREATE TABLE d_lp_fk_2 PARTITION OF d_lp_fk FOR VALUES IN (2); |
| 11 |
INSERT INTO d_lp_fk VALUES (1), (2); |
| 12 |
|
| 13 |
CREATE TABLE d_lp_fk_r (a int references d_lp_fk); |
| 14 |
} |
| 15 |
|
| 16 |
teardown { DROP TABLE IF EXISTS d_lp_fk, d_lp_fk_1, d_lp_fk_2, d_lp_fk_r; } |
| 17 |
|
| 18 |
session s1 |
| 19 |
step s1b { BEGIN; } |
| 20 |
step s1s { SELECT * FROM d_lp_fk; } |
| 21 |
step s1c { COMMIT; } |
| 22 |
|
| 23 |
session s2 |
| 24 |
step s2d { ALTER TABLE d_lp_fk DETACH PARTITION d_lp_fk_1 CONCURRENTLY; } |
| 25 |
|
| 26 |
session s3 |
| 27 |
step s3b { BEGIN; } |
| 28 |
step s3i1 { INSERT INTO d_lp_fk_r VALUES (1); } |
| 29 |
step s3i2 { INSERT INTO d_lp_fk_r VALUES (2); } |
| 30 |
step s3c { COMMIT; } |
| 31 |
|
| 32 |
# The transaction that detaches hangs until it sees any older transaction |
| 33 |
# terminate. |
| 34 |
permutation s1b s1s s2d s3i1 s1c |
| 35 |
permutation s1b s1s s2d s3i2 s3i2 s1c |
| 36 |
|
| 37 |
permutation s1b s1s s3i1 s2d s1c |
| 38 |
permutation s1b s1s s3i2 s2d s1c |
| 39 |
|
| 40 |
# what if s3 has an uncommitted insertion? |
| 41 |
permutation s1b s1s s3b s2d s3i1 s1c s3c |