Re: Add SPLIT PARTITION/MERGE PARTITIONS commands

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru>
Cc: Junwang Zhao <zhjwpku(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: 2025-06-11 13:22:22
Message-ID: CACJufxE=Qqtku4Ra3mZN-wQgdwyyHcwWN3jE=Wxfpwyd1UHZKQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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 Content-Type Size
v43-0001-check-if-we-can-drop-merging-partition-before-actuall.no-cfbot application/octet-stream 4.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Christoph Berg 2025-06-11 13:45:46 Re: CHECKPOINT unlogged data
Previous Message Yura Sokolov 2025-06-11 13:12:39 Re: Add 64-bit XIDs into PostgreSQL 15