Re: Add SPLIT PARTITION/MERGE PARTITIONS commands

From: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: Alexander Korotkov <aekorotkov(at)gmail(dot)com>, Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru>, Alexander Lakhin <exclusion(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: 2026-06-26 13:47:06
Message-ID: CALT9ZEG8F_oTZEp7vpqJH6Y4hGuQ6jEusETk+=C4XciedS0G1w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Justin!

On Fri, 26 Jun 2026 at 17:40, Justin Pryzby <pryzby(at)telsasoft(dot)com> wrote:
>
> Thanks for addressing the tablespace issue.
>
> One more thing -- merging non-contiguous tables is currently refused:
>
> ts=# CREATE TABLE a(t timestamptz) PARTITION BY RANGE (t);
> ts=# CREATE TABLE a_20260101 PARTITION OF a FOR VALUES FROM ('20260101')TO('20260102');
> ts=# CREATE TABLE a_20260126 PARTITION OF a FOR VALUES FROM ('20260126')TO('20260127');
> ts=# CREATE TABLE a_20260127 PARTITION OF a FOR VALUES FROM ('20260127')TO('20260128');
> ts=# CREATE TABLE a_20260128 PARTITION OF a FOR VALUES FROM ('20260128')TO('20260129');
>
> ts=# ALTER TABLE a MERGE PARTITIONS (a_20260101,a_20260126,a_20260127,a_20260128) INTO a_202601;
> ERROR: cannot merge partition "a_20260126" together with partition "a_20260101"
> DETAIL: The lower bound of partition "a_20260126" is not equal to the upper bound of partition "a_20260101".
> HINT: ALTER TABLE ... MERGE PARTITIONS requires the partition bounds to be adjacent.
>
> The goal seems to be to avoid overlapping partition constaints.
>
> If there's a default partition, that also avoids the possibility of
> needing to move *some* (but not all) tuples from it into the merged
> partition.
>
> I think there should be separate logic depending on the existance of a
> default partition:
>
> - The existing logic seems to correctly handle the case of a default
> partition, which is being merged (gap is allowed).
>
> - The case of a default partition which is not being merged is also
> handled: no gap is allowed. Actually, this case was probably the
> motivation behind checking that the partitions are adjacent.
>
> - If there's *no* default partition, then I think the check should be
> relaxed; it's sufficient to verify that the bounds of the merged
> partition do not overlap with any partition which is not being merged;

Thank you for reporting on this feature!
Yes, I think main motivation for not allowing a partition bounds gaps for
merge was the complication in case a DEFAULT partition exists.
Probably, this could be relaxed when there is no DEFAULT partition.

Regards,
Pavel Borisov
Supabase

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hüseyin Demir 2026-06-26 14:28:10 Re: Add autovacuum_warning to surface concurrent vacuum collisions
Previous Message Fujii Masao 2026-06-26 13:40:57 Re: 048_vacuum_horizon_floor.pl hangs due to wakeup lost inside LockBufferForCleanup