|
| 1 | +## PostgreSQL 17 preview - Implement `ALTER TABLE ... MERGE|SPLIT PARTITION` ... command |
| 2 | + |
| 3 | +### 作者 |
| 4 | +digoal |
| 5 | + |
| 6 | +### 日期 |
| 7 | +2024-04-07 |
| 8 | + |
| 9 | +### 标签 |
| 10 | +PostgreSQL , PolarDB , DuckDB , MERGE , SPLIT , partition |
| 11 | + |
| 12 | +---- |
| 13 | + |
| 14 | +## 背景 |
| 15 | +PostgreSQL 17 preview - Implement `ALTER TABLE ... MERGE|SPLIT PARTITION` ... command |
| 16 | + |
| 17 | +https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=1adf16b8fba45f77056d91573cd7138ed9da4ebf |
| 18 | + |
| 19 | +https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=87c21bb9412c8ba2727dec5ebcd74d44c2232d11 |
| 20 | + |
| 21 | +https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/test/regress/expected/partition_merge.out;h=2ba0ec47d97807cd55eb198f53798ca0f5bc1553;hb=1adf16b8fba45f77056d91573cd7138ed9da4ebf |
| 22 | + |
| 23 | +https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/test/regress/expected/partition_split.out;h=0a40f20554d74721bf1b06af36b4bba5dda8b47f;hb=87c21bb9412c8ba2727dec5ebcd74d44c2232d11 |
| 24 | + |
| 25 | +``` |
| 26 | + 130 ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO |
| 27 | + 131 (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), |
| 28 | + 132 PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), |
| 29 | + 133 PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); |
| 30 | + |
| 31 | + 427 ALTER TABLE salesmans MERGE PARTITIONS (salesmans10_20, salesmans20_30, salesmans30_40) INTO salesmans10_40; |
| 32 | +``` |
| 33 | + |
| 34 | +``` |
| 35 | +Implement ALTER TABLE ... SPLIT PARTITION ... command |
| 36 | +author Alexander Korotkov <[email protected]> |
| 37 | +Sat, 6 Apr 2024 21:58:09 +0000 (00:58 +0300) |
| 38 | +committer Alexander Korotkov <[email protected]> |
| 39 | +Sat, 6 Apr 2024 22:18:44 +0000 (01:18 +0300) |
| 40 | +commit 87c21bb9412c8ba2727dec5ebcd74d44c2232d11 |
| 41 | +tree 3ce4f8e030b40814f251997793066a6bac115f1f tree |
| 42 | +parent 1adf16b8fba45f77056d91573cd7138ed9da4ebf commit | diff |
| 43 | +Implement ALTER TABLE ... SPLIT PARTITION ... command |
| 44 | + |
| 45 | +This new DDL command splits a single partition into several parititions. |
| 46 | +Just like ALTER TABLE ... MERGE PARTITIONS ... command, new patitions are |
| 47 | +created using createPartitionTable() function with parent partition as the |
| 48 | +template. |
| 49 | + |
| 50 | +This commit comprises quite naive implementation which works in single process |
| 51 | +and holds the ACCESS EXCLUSIVE LOCK on the parent table during all the |
| 52 | +operations including the tuple routing. This is why this new DDL command |
| 53 | +can't be recommended for large partitioned tables under a high load. However, |
| 54 | +this implementation come in handy in certain cases even as is. |
| 55 | +Also, it could be used as a foundation for future implementations with lesser |
| 56 | +locking and possibly parallel. |
| 57 | + |
| 58 | +Discussion: https://postgr.es/m/c73a1746-0cd0-6bdd-6b23-3ae0b7c0c582%40postgrespro.ru |
| 59 | +Author: Dmitry Koval |
| 60 | +Reviewed-by: Matthias van de Meent, Laurenz Albe, Zhihong Yu, Justin Pryzby |
| 61 | +Reviewed-by: Alvaro Herrera, Robert Haas, Stephane Tachoires |
| 62 | +``` |
| 63 | + |
0 commit comments