]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Don't create SPLIT/MERGE partitions as internal relations
authorAlexander Korotkov <akorotkov@postgresql.org>
Wed, 8 Jul 2026 23:17:08 +0000 (02:17 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Wed, 8 Jul 2026 23:42:23 +0000 (02:42 +0300)
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 <noah@leadboat.com>
Discussion: https://postgr.es/m/20260707185751.f9.noahmisch@microsoft.com
Backpatch-through: 19

src/backend/commands/tablecmds.c

index 44bb18d34a0f3f9695035d61ca240c2934a080dc..de1afb60bbc5266146a23aaff1f4274df365575d 100644 (file)
@@ -22978,7 +22978,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
@@ -23046,7 +23046,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();
@@ -23108,7 +23108,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);
        }
 }
 
@@ -23228,7 +23228,7 @@ createPartitionTable(List **wqueue, RangeVar *newPartName,
                                                                                (Datum) 0,
                                                                                true,
                                                                                allowSystemTableMods,
-                                                                               true,
+                                                                               false,  /* is_internal */
                                                                                InvalidOid,
                                                                                NULL);
 
@@ -23800,7 +23800,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);
        }
 
        /*
@@ -24214,7 +24214,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