diff options
| author | Alvaro Herrera | 2021-04-28 19:44:35 +0000 |
|---|---|---|
| committer | Alvaro Herrera | 2021-04-28 19:44:35 +0000 |
| commit | d6b8d29419df0efad57f95c80b871745d1b55da6 (patch) | |
| tree | 04627e39b8fc7d19c55179eb4bdd898d7fc9aa29 /src/test/isolation | |
| parent | c93f8f3b8d3bc780892e2bf11192fbdd136fddfe (diff) | |
Allow a partdesc-omitting-partitions to be cached
Makes partition descriptor acquisition faster during the transient
period in which a partition is in the process of being detached.
This also adds the restriction that only one partition can be in
pending-detach state for a partitioned table.
While at it, return find_inheritance_children() API to what it was
before 71f4c8c6f74b, and create a separate
find_inheritance_children_extended() that returns detailed info about
detached partitions.
(This incidentally fixes a bug in 8aba9322511 whereby a memory context
holding a transient partdesc is reparented to a NULL PortalContext,
leading to permanent leak of that memory. The fix is to no longer rely
on reparenting contexts to PortalContext. Reported by Amit Langote.)
Per gripe from Amit Langote
Discussion: https://postgr.es/m/CA+HiwqFgpP1LxJZOBYGt9rpvTjXXkg5qG2+Xch2Z1Q7KrqZR1A@mail.gmail.com
Diffstat (limited to 'src/test/isolation')
| -rw-r--r-- | src/test/isolation/expected/detach-partition-concurrently-3.out | 110 | ||||
| -rw-r--r-- | src/test/isolation/specs/detach-partition-concurrently-3.spec | 14 |
2 files changed, 122 insertions, 2 deletions
diff --git a/src/test/isolation/expected/detach-partition-concurrently-3.out b/src/test/isolation/expected/detach-partition-concurrently-3.out index 88e83638c78..bbb9d151fb7 100644 --- a/src/test/isolation/expected/detach-partition-concurrently-3.out +++ b/src/test/isolation/expected/detach-partition-concurrently-3.out @@ -20,6 +20,7 @@ step s1describe: SELECT 'd3_listp' AS root, * FROM pg_partition_tree('d3_listp') root relid parentrelid isleaf level d3_listp d3_listp f 0 +d3_listp d3_listp2 d3_listp t 1 d3_listp1 d3_listp1 t 0 step s1alter: ALTER TABLE d3_listp1 ALTER a DROP NOT NULL; ERROR: cannot alter partition "d3_listp1" with an incomplete detach @@ -81,6 +82,59 @@ error in steps s1cancel s2detach: ERROR: canceling statement due to user reques step s1c: COMMIT; step s1insertpart: INSERT INTO d3_listp1 VALUES (1); +starting permutation: s2snitch s1b s1s s2detach2 s1cancel s1c s1brr s1insert s1s s1insert s1c +step s2snitch: INSERT INTO d3_pid SELECT pg_backend_pid(); +step s1b: BEGIN; +step s1s: SELECT * FROM d3_listp; +a + +1 +step s2detach2: ALTER TABLE d3_listp DETACH PARTITION d3_listp2 CONCURRENTLY; <waiting ...> +step s1cancel: SELECT pg_cancel_backend(pid) FROM d3_pid; +pg_cancel_backend + +t +step s2detach2: <... completed> +error in steps s1cancel s2detach2: ERROR: canceling statement due to user request +step s1c: COMMIT; +step s1brr: BEGIN ISOLATION LEVEL REPEATABLE READ; +step s1insert: INSERT INTO d3_listp VALUES (1); +step s1s: SELECT * FROM d3_listp; +a + +1 +1 +step s1insert: INSERT INTO d3_listp VALUES (1); +step s1c: COMMIT; + +starting permutation: s2snitch s1b s1s s2detach2 s1cancel s1c s1brr s1s s1insert s1s s1c +step s2snitch: INSERT INTO d3_pid SELECT pg_backend_pid(); +step s1b: BEGIN; +step s1s: SELECT * FROM d3_listp; +a + +1 +step s2detach2: ALTER TABLE d3_listp DETACH PARTITION d3_listp2 CONCURRENTLY; <waiting ...> +step s1cancel: SELECT pg_cancel_backend(pid) FROM d3_pid; +pg_cancel_backend + +t +step s2detach2: <... completed> +error in steps s1cancel s2detach2: ERROR: canceling statement due to user request +step s1c: COMMIT; +step s1brr: BEGIN ISOLATION LEVEL REPEATABLE READ; +step s1s: SELECT * FROM d3_listp; +a + +1 +step s1insert: INSERT INTO d3_listp VALUES (1); +step s1s: SELECT * FROM d3_listp; +a + +1 +1 +step s1c: COMMIT; + starting permutation: s2snitch s1b s1s s2detach s1cancel s1c s1drop s1list step s2snitch: INSERT INTO d3_pid SELECT pg_backend_pid(); step s1b: BEGIN; @@ -123,6 +177,61 @@ a 1 +starting permutation: s2snitch s1b s1s s2detach s1cancel s2detach2 s1c +step s2snitch: INSERT INTO d3_pid SELECT pg_backend_pid(); +step s1b: BEGIN; +step s1s: SELECT * FROM d3_listp; +a + +1 +step s2detach: ALTER TABLE d3_listp DETACH PARTITION d3_listp1 CONCURRENTLY; <waiting ...> +step s1cancel: SELECT pg_cancel_backend(pid) FROM d3_pid; +pg_cancel_backend + +t +step s2detach: <... completed> +error in steps s1cancel s2detach: ERROR: canceling statement due to user request +step s2detach2: ALTER TABLE d3_listp DETACH PARTITION d3_listp2 CONCURRENTLY; +ERROR: partition "d3_listp1" already pending detach in partitioned table "public.d3_listp" +step s1c: COMMIT; + +starting permutation: s2snitch s1b s1s s2detach s1cancel s2detachfinal s1c s2detach2 +step s2snitch: INSERT INTO d3_pid SELECT pg_backend_pid(); +step s1b: BEGIN; +step s1s: SELECT * FROM d3_listp; +a + +1 +step s2detach: ALTER TABLE d3_listp DETACH PARTITION d3_listp1 CONCURRENTLY; <waiting ...> +step s1cancel: SELECT pg_cancel_backend(pid) FROM d3_pid; +pg_cancel_backend + +t +step s2detach: <... completed> +error in steps s1cancel s2detach: ERROR: canceling statement due to user request +step s2detachfinal: ALTER TABLE d3_listp DETACH PARTITION d3_listp1 FINALIZE; <waiting ...> +step s1c: COMMIT; +step s2detachfinal: <... completed> +step s2detach2: ALTER TABLE d3_listp DETACH PARTITION d3_listp2 CONCURRENTLY; + +starting permutation: s2snitch s1b s1s s2detach s1cancel s1c s1droppart s2detach2 +step s2snitch: INSERT INTO d3_pid SELECT pg_backend_pid(); +step s1b: BEGIN; +step s1s: SELECT * FROM d3_listp; +a + +1 +step s2detach: ALTER TABLE d3_listp DETACH PARTITION d3_listp1 CONCURRENTLY; <waiting ...> +step s1cancel: SELECT pg_cancel_backend(pid) FROM d3_pid; +pg_cancel_backend + +t +step s2detach: <... completed> +error in steps s1cancel s2detach: ERROR: canceling statement due to user request +step s1c: COMMIT; +step s1droppart: DROP TABLE d3_listp1; +step s2detach2: ALTER TABLE d3_listp DETACH PARTITION d3_listp2 CONCURRENTLY; + starting permutation: s2snitch s1b s1s s2detach s1cancel s1c s2begin s2drop s1s s2commit step s2snitch: INSERT INTO d3_pid SELECT pg_backend_pid(); step s1b: BEGIN; @@ -279,4 +388,3 @@ step s2detachfinal: ALTER TABLE d3_listp DETACH PARTITION d3_listp1 FINALIZE; step s1insertpart: INSERT INTO d3_listp1 VALUES (1); <waiting ...> step s2commit: COMMIT; step s1insertpart: <... completed> -unused step name: s1droppart diff --git a/src/test/isolation/specs/detach-partition-concurrently-3.spec b/src/test/isolation/specs/detach-partition-concurrently-3.spec index 4b706430e13..5a8351fc83e 100644 --- a/src/test/isolation/specs/detach-partition-concurrently-3.spec +++ b/src/test/isolation/specs/detach-partition-concurrently-3.spec @@ -4,12 +4,13 @@ setup { CREATE TABLE d3_listp (a int) PARTITION BY LIST(a); CREATE TABLE d3_listp1 PARTITION OF d3_listp FOR VALUES IN (1); + CREATE TABLE d3_listp2 PARTITION OF d3_listp FOR VALUES IN (2); CREATE TABLE d3_pid (pid int); INSERT INTO d3_listp VALUES (1); } teardown { - DROP TABLE IF EXISTS d3_listp, d3_listp1, d3_pid; + DROP TABLE IF EXISTS d3_listp, d3_listp1, d3_listp2, d3_pid; } session "s1" @@ -34,6 +35,7 @@ session "s2" step "s2begin" { BEGIN; } step "s2snitch" { INSERT INTO d3_pid SELECT pg_backend_pid(); } step "s2detach" { ALTER TABLE d3_listp DETACH PARTITION d3_listp1 CONCURRENTLY; } +step "s2detach2" { ALTER TABLE d3_listp DETACH PARTITION d3_listp2 CONCURRENTLY; } step "s2detachfinal" { ALTER TABLE d3_listp DETACH PARTITION d3_listp1 FINALIZE; } step "s2drop" { DROP TABLE d3_listp1; } step "s2commit" { COMMIT; } @@ -44,11 +46,21 @@ permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s1c" "s1describe" "s1a permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s1insert" "s1c" permutation "s2snitch" "s1brr" "s1s" "s2detach" "s1cancel" "s1insert" "s1c" "s1spart" permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s1c" "s1insertpart" + +# Test partition descriptor caching +permutation "s2snitch" "s1b" "s1s" "s2detach2" "s1cancel" "s1c" "s1brr" "s1insert" "s1s" "s1insert" "s1c" +permutation "s2snitch" "s1b" "s1s" "s2detach2" "s1cancel" "s1c" "s1brr" "s1s" "s1insert" "s1s" "s1c" + # "drop" here does both tables permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s1c" "s1drop" "s1list" # "truncate" only does parent, not partition permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s1c" "s1trunc" "s1spart" +# If a partition pending detach exists, we cannot drop another one +permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s2detach2" "s1c" +permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s2detachfinal" "s1c" "s2detach2" +permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s1c" "s1droppart" "s2detach2" + # When a partition with incomplete detach is dropped, we grab lock on parent too. permutation "s2snitch" "s1b" "s1s" "s2detach" "s1cancel" "s1c" "s2begin" "s2drop" "s1s" "s2commit" |
