Re: Add SPLIT PARTITION/MERGE PARTITIONS commands

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Cc: Pavel Borisov <pashkin(dot)elfe(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:40:14
Message-ID: aj6BPoziSb-F8aJz@pryzbyj2023
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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;

--
Justin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-06-26 13:40:57 Re: 048_vacuum_horizon_floor.pl hangs due to wakeup lost inside LockBufferForCleanup
Previous Message Isaac Morland 2026-06-26 13:21:11 Re: ON EMPTY clause for aggregate and window functions