Implement ALTER TABLE ... MERGE PARTITIONS ... command
authorAlexander Korotkov <akorotkov@postgresql.org>
Sat, 6 Apr 2024 21:57:22 +0000 (00:57 +0300)
committerAlexander Korotkov <akorotkov@postgresql.org>
Sat, 6 Apr 2024 22:18:43 +0000 (01:18 +0300)
commit1adf16b8fba45f77056d91573cd7138ed9da4ebf
treeee8cddd9d9883aab432ddcb3e328bda0e851c953
parentfe1431e39cdde5f65cb52f068bc86a7490f8a4e3
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
17 files changed:
doc/src/sgml/ddl.sgml
doc/src/sgml/ref/alter_table.sgml
src/backend/commands/tablecmds.c
src/backend/parser/gram.y
src/backend/parser/parse_utilcmd.c
src/backend/partitioning/partbounds.c
src/include/nodes/parsenodes.h
src/include/parser/kwlist.h
src/include/partitioning/partbounds.h
src/test/isolation/expected/partition-merge.out [new file with mode: 0644]
src/test/isolation/isolation_schedule
src/test/isolation/specs/partition-merge.spec [new file with mode: 0644]
src/test/modules/test_ddl_deparse/test_ddl_deparse.c
src/test/regress/expected/partition_merge.out [new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/sql/partition_merge.sql [new file with mode: 0644]
src/tools/pgindent/typedefs.list