1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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 <noah@leadboat.com>
Discussion: https://postgr.es/m/20260707185751.f9.noahmisch@microsoft.com
Backpatch-through: 19
This commit is contained in:
Alexander Korotkov
2026-07-09 02:17:08 +03:00
parent 5e90e0914c
commit 881033ae8b

View File

@@ -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