diff options
author | Michael Paquier <michael@paquier.xyz> | 2021-12-22 15:38:05 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2021-12-22 15:38:05 +0900 |
commit | 8a22a40b2cfd1ea3218663153e5c6d7ebc68d2bf (patch) | |
tree | e02f65ea5f057f873df40deb11b18ffedaaaf50c | |
parent | f9a8bc9f27e6c7569f30fc86b82129647068f6a0 (diff) | |
download | postgresql-8a22a40b2cfd1ea3218663153e5c6d7ebc68d2bf.tar.gz postgresql-8a22a40b2cfd1ea3218663153e5c6d7ebc68d2bf.zip |
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
-rw-r--r-- | contrib/postgres_fdw/expected/postgres_fdw.out | 3 | ||||
-rw-r--r-- | contrib/postgres_fdw/sql/postgres_fdw.sql | 3 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 2 |
3 files changed, 6 insertions, 2 deletions
diff --git a/contrib/postgres_fdw/expected/postgres_fdw.out b/contrib/postgres_fdw/expected/postgres_fdw.out index d5dc0ce0c56..b62337bd970 100644 --- a/contrib/postgres_fdw/expected/postgres_fdw.out +++ b/contrib/postgres_fdw/expected/postgres_fdw.out @@ -6342,6 +6342,9 @@ CREATE FOREIGN TABLE foreign_tbl (a int, b int) SERVER loopback OPTIONS (table_name 'child_tbl'); CREATE TABLE parent_tbl (a int, b int) PARTITION BY RANGE(a); ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100); +-- Detach and re-attach once, to stress the concurrent detach case. +ALTER TABLE parent_tbl DETACH PARTITION foreign_tbl CONCURRENTLY; +ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100); CREATE VIEW rw_view AS SELECT * FROM parent_tbl WHERE a < b WITH CHECK OPTION; \d+ rw_view diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql index ef45b3f91c9..ee9ab37d565 100644 --- a/contrib/postgres_fdw/sql/postgres_fdw.sql +++ b/contrib/postgres_fdw/sql/postgres_fdw.sql @@ -1438,6 +1438,9 @@ CREATE FOREIGN TABLE foreign_tbl (a int, b int) CREATE TABLE parent_tbl (a int, b int) PARTITION BY RANGE(a); ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100); +-- Detach and re-attach once, to stress the concurrent detach case. +ALTER TABLE parent_tbl DETACH PARTITION foreign_tbl CONCURRENTLY; +ALTER TABLE parent_tbl ATTACH PARTITION foreign_tbl FOR VALUES FROM (0) TO (100); CREATE VIEW rw_view AS SELECT * FROM parent_tbl WHERE a < b WITH CHECK OPTION; diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index b9ea5280efa..85cb3b22a0b 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -14787,8 +14787,6 @@ MarkInheritDetached(Relation child_rel, Relation parent_rel) HeapTuple inheritsTuple; bool found = false; - Assert(child_rel->rd_rel->relkind == RELKIND_RELATION || - child_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE); Assert(parent_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE); /* |