hi.

+ /* Copy data from merged partitions to new partition. */
+ moveMergedTablesRows(rel, mergingPartitionsList, newPartRel);
+
+ /* Drop the current partitions before attaching the new one. */
+ foreach_ptr(RelationData, mergingPartition, mergingPartitionsList)
+ {
+ ObjectAddress object;
+
+ /* Get relation id before table_close() call. */
+ object.objectId = RelationGetRelid(mergingPartition);
+ object.classId = RelationRelationId;
+ object.objectSubId = 0;
+
+ /* Keep the lock until commit. */
+ table_close(mergingPartition, NoLock);
+
+ performDeletion(&object, DROP_RESTRICT, 0);
+ }
+ list_free(mergingPartitionsList);
In here, should performDeletion last flags have PERFORM_DELETION_INTERNAL?

also this is not ideal, imagine you first did all the main work in
moveMergedTablesRows,
then suddenly error out, saying:

ERROR:  cannot drop table public.pk_1 because other objects depend on it
DETAIL:  view public.v1 depends on table public.pk_1
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
(this errhint, seems not ideal in this context)

We can perform a preliminary check to determine whether dropping a partition is
allowed, and raise an error if it's not. To do it, I invented a new
function, performDeletionCheck to verify whether an object can be
safely dropped.

please check attached, it was based on v43.

Attachment: v43-0001-check-if-we-can-drop-merging-partition-before-actuall.no-cfbot
Description: Binary data

Reply via email to