public inbox for [email protected]  
help / color / mirror / Atom feed
From: jian he <[email protected]>
To: Dmitry Koval <[email protected]>
Cc: Junwang Zhao <[email protected]>
Cc: [email protected]
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: Wed, 11 Jun 2025 21:22:22 +0800
Message-ID: <CACJufxE=Qqtku4Ra3mZN-wQgdwyyHcwWN3jE=Wxfpwyd1UHZKQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <171085360143.2046436.7217841141682511557.pgcf@coridan.postgresql.org>
	<[email protected]>
	<CAPpHfdv2V2tsvVn5LYyrJkzmPA==vbdCEKiT8j9yaaiDTfaQtA@mail.gmail.com>
	<[email protected]>
	<CALDaNm3V5DQSbZGxhYH+3MMMm-YdgOg+RdJ-ni6D0TZx_=Xd7w@mail.gmail.com>
	<[email protected]>
	<CAPpHfduH83+CW1dBppFVjxauPFGC+-ux+Y7wB0koZJCs029SXA@mail.gmail.com>
	<[email protected]>
	<CACJufxEi_JVg+=_BSS0o+TYUE_Hq+jmga_yxxuKLSGbQiAnZDg@mail.gmail.com>
	<[email protected]>
	<CACJufxFGPLTDW55bgaBTH1uCf0=YUZUVKWFrTBvOZNYKc49MxA@mail.gmail.com>
	<CACJufxHHnJm6Jb2YQpuRU1RX__tO=JJNJ5=EUMuzif_KNxGd9A@mail.gmail.com>
	<CACJufxFkscyhak2cSr8t+EPfwv11yccfEZBBnPbX4tRc_mWkXQ@mail.gmail.com>
	<[email protected]>
	<CAEG8a3Lpw-h+T+Pfqcchyc9mp0r5UcWT5+uZYsew=1ZSkg-H+w@mail.gmail.com>
	<[email protected]>

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.


Attachments:

  [application/octet-stream] v43-0001-check-if-we-can-drop-merging-partition-before-actuall.no-cfbot (4.1K, ../CACJufxE=Qqtku4Ra3mZN-wQgdwyyHcwWN3jE=Wxfpwyd1UHZKQ@mail.gmail.com/2-v43-0001-check-if-we-can-drop-merging-partition-before-actuall.no-cfbot)
  download

view thread (178+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  In-Reply-To: <CACJufxE=Qqtku4Ra3mZN-wQgdwyyHcwWN3jE=Wxfpwyd1UHZKQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox