Skip to content

Commit 8a22a40

Browse files
committed
Remove assertion for ALTER TABLE .. DETACH PARTITION CONCURRENTLY
One code path related to this flavor of ALTER TABLE was checking that the relation to detach has to be a normal table or a partitioned table, which would fail if using the command with a different relation kind. Views, sequences and materialized views cannot be part of a partition tree, so these would cause the command to fail anyway, but the assertion was triggered. Foreign tables can be part of a partition tree, and again the assertion would have failed. The simplest solution is just to remove this assertion, so as we get the same failure as the non-concurrent code path. While on it, add a regression test in postgres_fdw for the concurrent partition detach of a foreign table, as per a suggestion from Alexander Lakhin. Issue introduced in 71f4c8c. Reported-by: Alexander Lakhin Author: Michael Paquier, Alexander Lakhin Reviewed-by: Peter Eisentraut, Kyotaro Horiguchi Discussion: https://postgr.es/m/17339-a9e09aaf38a3457a@postgresql.org Backpatch-through: 14
1 parent f9a8bc9 commit 8a22a40

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6342,6 +6342,9 @@ CREATE FOREIGN TABLE foreign_tbl (a int, b int)
63426342
SERVER loopback OPTIONS (table_name 'child_tbl');
63436343
CREATE TABLE parent_tbl (a int, b int) PARTITION BY RANGE(a);
63446344
ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100);
6345+
-- Detach and re-attach once, to stress the concurrent detach case.
6346+
ALTER TABLE parent_tbl DETACH PARTITION foreign_tbl CONCURRENTLY;
6347+
ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100);
63456348
CREATE VIEW rw_view AS SELECT * FROM parent_tbl
63466349
WHERE a < b WITH CHECK OPTION;
63476350
\d+ rw_view

contrib/postgres_fdw/sql/postgres_fdw.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,9 @@ CREATE FOREIGN TABLE foreign_tbl (a int, b int)
14381438

14391439
CREATE TABLE parent_tbl (a int, b int) PARTITION BY RANGE(a);
14401440
ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100);
1441+
-- Detach and re-attach once, to stress the concurrent detach case.
1442+
ALTER TABLE parent_tbl DETACH PARTITION foreign_tbl CONCURRENTLY;
1443+
ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100);
14411444

14421445
CREATE VIEW rw_view AS SELECT * FROM parent_tbl
14431446
WHERE a < b WITH CHECK OPTION;

src/backend/commands/tablecmds.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14787,8 +14787,6 @@ MarkInheritDetached(Relation child_rel, Relation parent_rel)
1478714787
HeapTuple inheritsTuple;
1478814788
bool found = false;
1478914789

14790-
Assert(child_rel->rd_rel->relkind == RELKIND_RELATION ||
14791-
child_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
1479214790
Assert(parent_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE);
1479314791

1479414792
/*

0 commit comments

Comments
 (0)