From: Alexander Korotkov Date: Wed, 8 Jul 2026 23:17:08 +0000 (+0300) Subject: Don't create SPLIT/MERGE partitions as internal relations X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=881033ae8b55dbd22f7ee9c26991b6c4e67d6bd5;p=thirdparty%2Fpostgresql.git Don't create SPLIT/MERGE partitions as internal relations The new partitions built for ALTER TABLE ... SPLIT PARTITION and ALTER TABLE ... MERGE PARTITIONS are created at the explicit request of the user, just like a plain CREATE TABLE. createPartitionTable() passes is_internal=true to heap_create_with_catalog(), while createTableConstraints() does the same to StoreAttrDefault() and AddRelationNewConstraints(). Pass is_internal=false in all these places instead, so that object-access hooks treat them as user-requested objects. The is_internal flag is intended for objects created as internal implementation details, such as a transient heap built during CLUSTER. While at it, pass 0 rather than PERFORM_DELETION_INTERNAL to the performDeletionCheck() calls that pre-check the drop eligibility of the old partitions, to match the subsequent performDeletion(). The flag has no functional effect on performDeletionCheck(), but change this for code consistency. Reported-by: Noah Misch Discussion: https://postgr.es/m/20260707185751.f9.noahmisch@microsoft.com Backpatch-through: 19 --- diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index b116e70a4bf..cb93c3e935a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -23063,7 +23063,7 @@ createTableConstraints(List **wqueue, AlteredTableInfo *tab, elog(ERROR, "cannot convert whole-row table reference"); /* Add a pre-cooked default expression. */ - StoreAttrDefault(newRel, num, def, true); + StoreAttrDefault(newRel, num, def, false); /* * Stored generated column expressions in parent_rel might @@ -23131,7 +23131,7 @@ createTableConstraints(List **wqueue, AlteredTableInfo *tab, /* Install all CHECK constraints. */ cookedConstraints = AddRelationNewConstraints(newRel, NIL, constraints, - false, true, true, NULL); + false, true, false, NULL); /* Make the additional catalog changes visible. */ CommandCounterIncrement(); @@ -23193,7 +23193,7 @@ createTableConstraints(List **wqueue, AlteredTableInfo *tab, * We already set pg_attribute.attnotnull in createPartitionTable. No * need call set_attnotnull again. */ - AddRelationNewConstraints(newRel, NIL, nnconstraints, false, true, true, NULL); + AddRelationNewConstraints(newRel, NIL, nnconstraints, false, true, false, NULL); } } @@ -23313,7 +23313,7 @@ createPartitionTable(List **wqueue, RangeVar *newPartName, (Datum) 0, true, allowSystemTableMods, - true, + false, /* is_internal */ InvalidOid, NULL); @@ -23885,7 +23885,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel, object.classId = RelationRelationId; object.objectSubId = 0; - performDeletionCheck(&object, DROP_RESTRICT, PERFORM_DELETION_INTERNAL); + performDeletionCheck(&object, DROP_RESTRICT, 0); } /* @@ -24299,7 +24299,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, object.objectId = splitRelOid; object.classId = RelationRelationId; object.objectSubId = 0; - performDeletionCheck(&object, DROP_RESTRICT, PERFORM_DELETION_INTERNAL); + performDeletionCheck(&object, DROP_RESTRICT, 0); /* * If a new partition has the same name as the split partition, then we