From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Subject: [PATCH] Reset relhassubclass when attaching as a partition
Date: Tue, 23 Jul 2024 18:49:58 +0200
---
src/backend/catalog/heap.c | 8 ++++++++
src/test/regress/expected/create_table.out | 12 ++++++++++++
src/test/regress/sql/create_table.sql | 11 +++++++++++
3 files changed, 31 insertions(+)
inline patch 1: src/backend/catalog/heap.c, src/test/regress/expected/create_table.out, src/test/regress/sql/create_table.sql (+31/-0 lines) download inline-1.patchdiff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.cindex 0bf9625cc9..e1c66c53df 100644--- a/src/backend/catalog/heap.c+++ b/src/backend/catalog/heap.c@@ -3849,6 +3849,14 @@ StorePartitionBound(Relation rel, Relation parent, PartitionBoundSpec *bound)
new_val, new_null, new_repl);
/* Also set the flag */
((Form_pg_class) GETSTRUCT(newtuple))->relispartition = true;
++ /*+ * Already checked for no children, but reset relhassubclass in case it was+ * left over.+ */+ if (rel->rd_rel->relkind == RELKIND_RELATION && rel->rd_rel->relhassubclass)+ ((Form_pg_class) GETSTRUCT(newtuple))->relhassubclass = false;+
CatalogTupleUpdate(classRel, &newtuple->t_self, newtuple);
heap_freetuple(newtuple);
table_close(classRel, RowExclusiveLock);
diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.outindex a958b84979..374d0f10e8 100644--- a/src/test/regress/expected/create_table.out+++ b/src/test/regress/expected/create_table.out@@ -1270,6 +1270,18 @@ insert into defcheck_def values (0, 0);
create table defcheck_0 partition of defcheck for values in (0);
ERROR: updated partition constraint for default partition "defcheck_def" would be violated by some row
drop table defcheck;
+-- test that we can use a table that was an inheritance parent+-- as a partition. (Bug #18550)+create table part_test_18550_1 (a int);+create table part_test_18550_2 () inherits (part_test_18550_1);+drop table part_test_18550_2;+create table part_test_18550 (a int) partition by list (a);+alter table part_test_18550 attach partition part_test_18550_1 for values in (1);+insert into part_test_18550_1 values (1);+update part_test_18550_1 set a = 2 where a = 1;+ERROR: new row for relation "part_test_18550_1" violates partition constraint+DETAIL: Failing row contains (2).+drop table part_test_18550;
-- tests of column drop with partition tables and indexes using
-- predicates and expressions.
create table part_column_drop (
diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sqlindex cc41f58ba2..91e5ec73ee 100644--- a/src/test/regress/sql/create_table.sql+++ b/src/test/regress/sql/create_table.sql@@ -953,6 +953,17 @@ insert into defcheck_def values (0, 0);
create table defcheck_0 partition of defcheck for values in (0);
drop table defcheck;
+-- test that we can use a table that was an inheritance parent+-- as a partition. (Bug #18550)+create table part_test_18550_1 (a int);+create table part_test_18550_2 () inherits (part_test_18550_1);+drop table part_test_18550_2;+create table part_test_18550 (a int) partition by list (a);+alter table part_test_18550 attach partition part_test_18550_1 for values in (1);+insert into part_test_18550_1 values (1);+update part_test_18550_1 set a = 2 where a = 1;+drop table part_test_18550;+
-- tests of column drop with partition tables and indexes using
-- predicates and expressions.
create table part_column_drop (
--
2.39.2
--tzghwpfillwk4o4f--
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: alvherre@alvh.no-ip.org
Subject: Re: [PATCH] Reset relhassubclass when attaching as a partition
In-Reply-To: <no-message-id-25515@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox