summaryrefslogtreecommitdiff
path: root/src/include/nodes
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2025-12-14 13:29:38 +0200
committerAlexander Korotkov <akorotkov@postgresql.org>2025-12-14 13:29:38 +0200
commit4b3d173629f4cd7ab6cd700d1053af5d5c7c9e37 (patch)
tree79d024319e181b99718b9725d5e472b069e7414c /src/include/nodes
parentf2e4cc427951b7c46629fb7625a22f7898586f3a (diff)
Implement ALTER TABLE ... SPLIT PARTITION ... command
This new DDL command splits a single partition into several partitions. Just like the ALTER TABLE ... MERGE PARTITIONS ... command, new partitions are created using the createPartitionTable() function with the parent partition as the template. This commit comprises a quite naive implementation which works in a single process and holds the ACCESS EXCLUSIVE LOCK on the parent table during all the operations, including the tuple routing. This is why the new DDL command can't be recommended for large, partitioned tables under high load. However, this implementation comes in handy in certain cases, even as it is. Also, it could serve as a foundation for future implementations with less locking and possibly parallelism. Discussion: https://postgr.es/m/c73a1746-0cd0-6bdd-6b23-3ae0b7c0c582%40postgrespro.ru Author: Dmitry Koval <d.koval@postgrespro.ru> Co-authored-by: Alexander Korotkov <aekorotkov@gmail.com> Co-authored-by: Tender Wang <tndrwang@gmail.com> Co-authored-by: Richard Guo <guofenglinux@gmail.com> Co-authored-by: Dagfinn Ilmari Mannsaker <ilmari@ilmari.org> Co-authored-by: Fujii Masao <masao.fujii@gmail.com> Co-authored-by: Jian He <jian.universality@gmail.com> Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com> Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at> Reviewed-by: Zhihong Yu <zyu@yugabyte.com> Reviewed-by: Justin Pryzby <pryzby@telsasoft.com> Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> Reviewed-by: Robert Haas <rhaas@postgresql.org> Reviewed-by: Stephane Tachoires <stephane.tachoires@gmail.com> Reviewed-by: Jian He <jian.universality@gmail.com> Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com> Reviewed-by: Pavel Borisov <pashkin.elfe@gmail.com> Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com> Reviewed-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: Daniel Gustafsson <dgustafsson@postgresql.org> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Noah Misch <noah@leadboat.com>
Diffstat (limited to 'src/include/nodes')
-rw-r--r--src/include/nodes/parsenodes.h34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index e43a1f946a9..bc7adba4a0f 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -966,16 +966,39 @@ typedef struct PartitionRangeDatum
} PartitionRangeDatum;
/*
+ * PartitionDesc - info about a single partition for the ALTER TABLE SPLIT
+ * PARTITION command
+ */
+typedef struct SinglePartitionSpec
+{
+ NodeTag type;
+
+ RangeVar *name; /* name of partition */
+ PartitionBoundSpec *bound; /* FOR VALUES, if attaching */
+} SinglePartitionSpec;
+
+/*
* PartitionCmd - info for ALTER TABLE/INDEX ATTACH/DETACH PARTITION and for
- * ALTER TABLE MERGE PARTITIONS commands
+ * ALTER TABLE SPLIT/MERGE PARTITION(S) commands
*/
typedef struct PartitionCmd
{
NodeTag type;
- RangeVar *name; /* name of partition to attach/detach/merge */
- PartitionBoundSpec *bound; /* FOR VALUES, if attaching */
- List *partlist; /* list of partitions to be merged, used in
- * ALTER TABLE MERGE PARTITIONS */
+
+ /* name of partition to attach/detach/merge/split */
+ RangeVar *name;
+
+ /* FOR VALUES, if attaching */
+ PartitionBoundSpec *bound;
+
+ /*
+ * list of partitions to be split/merged, used in ALTER TABLE MERGE
+ * PARTITIONS and ALTER TABLE SPLIT PARTITIONS. For merge partitions,
+ * partlist is a list of RangeVar; For split partition, it is a list of
+ * SinglePartitionSpec.
+ */
+ List *partlist;
+
bool concurrent;
} PartitionCmd;
@@ -2479,6 +2502,7 @@ typedef enum AlterTableType
AT_AttachPartition, /* ATTACH PARTITION */
AT_DetachPartition, /* DETACH PARTITION */
AT_DetachPartitionFinalize, /* DETACH PARTITION FINALIZE */
+ AT_SplitPartition, /* SPLIT PARTITION */
AT_MergePartitions, /* MERGE PARTITIONS */
AT_AddIdentity, /* ADD IDENTITY */
AT_SetIdentity, /* SET identity column options */