pgsql: Implement ALTER TABLE ... MERGE PARTITIONS ... command

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Implement ALTER TABLE ... MERGE PARTITIONS ... command
Date: 2024-04-06 22:19:06
Message-ID: E1rtENN-000rrU-RZ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Implement ALTER TABLE ... MERGE PARTITIONS ... command

This new DDL command merges several partitions into the one partition of the
target table. The target partition is created using new
createPartitionTable() function with parent partition as the template.

This commit comprises quite naive implementation which works in single process
and holds the ACCESS EXCLUSIVE LOCK on the parent table during all the
operations including the tuple routing. This is why this new DDL command
can't be recommended for large partitioned tables under a high load. However,
this implementation come in handy in certain cases even as is.
Also, it could be used as a foundation for future implementations with lesser
locking and possibly parallel.

Discussion: https://postgr.es/m/c73a1746-0cd0-6bdd-6b23-3ae0b7c0c582%40postgrespro.ru
Author: Dmitry Koval
Reviewed-by: Matthias van de Meent, Laurenz Albe, Zhihong Yu, Justin Pryzby
Reviewed-by: Alvaro Herrera, Robert Haas, Stephane Tachoires

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1adf16b8fba45f77056d91573cd7138ed9da4ebf

Modified Files
--------------
doc/src/sgml/ddl.sgml | 19 +
doc/src/sgml/ref/alter_table.sgml | 77 ++-
src/backend/commands/tablecmds.c | 354 +++++++++-
src/backend/parser/gram.y | 22 +-
src/backend/parser/parse_utilcmd.c | 89 +++
src/backend/partitioning/partbounds.c | 207 ++++++
src/include/nodes/parsenodes.h | 14 +
src/include/parser/kwlist.h | 1 +
src/include/partitioning/partbounds.h | 6 +
src/test/isolation/expected/partition-merge.out | 199 ++++++
src/test/isolation/isolation_schedule | 1 +
src/test/isolation/specs/partition-merge.spec | 54 ++
.../modules/test_ddl_deparse/test_ddl_deparse.c | 3 +
src/test/regress/expected/partition_merge.out | 732 +++++++++++++++++++++
src/test/regress/parallel_schedule | 2 +-
src/test/regress/sql/partition_merge.sql | 430 ++++++++++++
src/tools/pgindent/typedefs.list | 1 +
17 files changed, 2189 insertions(+), 22 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tomas Vondra 2024-04-06 22:26:19 pgsql: BitmapHeapScan: Push skip_fetch optimization into table AM
Previous Message Tomas Vondra 2024-04-06 21:57:14 pgsql: BitmapHeapScan: postpone setting can_skip_fetch