Skip to content

Commit b23712b

Browse files
committed
refresh README.md
1 parent 51aa9d2 commit b23712b

File tree

1 file changed

+49
-28
lines changed

1 file changed

+49
-28
lines changed

README.md

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ More interesting features are yet to come. Stay tuned!
6363
* Effective query planning for partitioned tables (JOINs, subselects etc);
6464
* `RuntimeAppend` & `RuntimeMergeAppend` custom plan nodes to pick partitions at runtime;
6565
* `PartitionFilter`: an efficient drop-in replacement for INSERT triggers;
66+
* `PartitionRouter` for cross-partition UPDATE queries (instead of triggers);
6667
* Automatic partition creation for new INSERTed data (only for RANGE partitioning);
6768
* Improved `COPY FROM` statement that is able to insert rows directly into partitions;
68-
* UPDATE triggers generation out of the box (will be replaced with custom nodes too);
6969
* User-defined callbacks for partition creation event handling;
7070
* Non-blocking concurrent table partitioning;
7171
* FDW support (foreign partitions);
72-
* Various GUC toggles and configurable settings.
72+
* Various [GUC](#disabling-pg_pathman) toggles and configurable settings.
7373

7474
## Installation guide
7575
To install `pg_pathman`, execute this in the module's directory:
@@ -121,8 +121,8 @@ Although it's possible to get major and minor version numbers using `\dx pg_path
121121

122122
### Partition creation
123123
```plpgsql
124-
create_hash_partitions(relation REGCLASS,
125-
expr TEXT,
124+
create_hash_partitions(parent_relid REGCLASS,
125+
expression TEXT,
126126
partitions_count INTEGER,
127127
partition_data BOOLEAN DEFAULT TRUE,
128128
partition_names TEXT[] DEFAULT NULL,
@@ -131,21 +131,21 @@ create_hash_partitions(relation REGCLASS,
131131
Performs HASH partitioning for `relation` by partitioning expression `expr`. The `partitions_count` parameter specifies the number of partitions to create; it cannot be changed afterwards. If `partition_data` is `true` then all the data will be automatically copied from the parent table to partitions. Note that data migration may took a while to finish and the table will be locked until transaction commits. See `partition_table_concurrently()` for a lock-free way to migrate data. Partition creation callback is invoked for each partition if set beforehand (see `set_init_callback()`).
132132

133133
```plpgsql
134-
create_range_partitions(relation REGCLASS,
134+
create_range_partitions(parent_relid REGCLASS,
135135
expression TEXT,
136136
start_value ANYELEMENT,
137137
p_interval ANYELEMENT,
138138
p_count INTEGER DEFAULT NULL
139139
partition_data BOOLEAN DEFAULT TRUE)
140140

141-
create_range_partitions(relation REGCLASS,
141+
create_range_partitions(parent_relid REGCLASS,
142142
expression TEXT,
143143
start_value ANYELEMENT,
144144
p_interval INTERVAL,
145145
p_count INTEGER DEFAULT NULL,
146146
partition_data BOOLEAN DEFAULT TRUE)
147147

148-
create_range_partitions(relation REGCLASS,
148+
create_range_partitions(parent_relid REGCLASS,
149149
expression TEXT,
150150
bounds ANYARRAY,
151151
partition_names TEXT[] DEFAULT NULL,
@@ -181,10 +181,12 @@ stop_concurrent_part_task(relation REGCLASS)
181181
Stops a background worker performing a concurrent partitioning task. Note: worker will exit after it finishes relocating a current batch.
182182

183183
### Triggers
184-
```plpgsql
185-
create_update_triggers(parent REGCLASS)
186-
```
187-
Creates a for-each-row trigger to enable cross-partition UPDATE on a table partitioned by HASH/RANGE. The trigger is not created automatically because of the overhead caused by its function. You don't have to use this feature unless partitioning key might change during an UPDATE.
184+
185+
Triggers are no longer required nor for INSERTs, neither for cross-partition UPDATEs. However, user-supplied triggers *are supported*.
186+
187+
Each inserted row results in execution of BEFORE/AFTER INSERT trigger functions of a **corresponding partition**.
188+
Each updated row results in execution of BEFORE/AFTER UPDATE trigger functions of a **corresponding partition**.
189+
Each moved row (cross-partition update) results in execution of BEFORE UPDATE + BEFORE/AFTER DELETE + BEFORE/AFTER INSERT trigger functions of **corresponding partitions**.
188190

189191
### Post-creation partition management
190192
```plpgsql
@@ -196,9 +198,10 @@ Replaces specified partition of HASH-partitioned table with another table. The `
196198

197199

198200
```plpgsql
199-
split_range_partition(partition REGCLASS,
200-
split_value ANYELEMENT,
201-
partition_name TEXT DEFAULT NULL)
201+
split_range_partition(partition_relid REGCLASS,
202+
split_value ANYELEMENT,
203+
partition_name TEXT DEFAULT NULL,
204+
tablespace TEXT DEFAULT NULL)
202205
```
203206
Split RANGE `partition` in two by `split_value`. Partition creation callback is invoked for a new partition if available.
204207

@@ -208,21 +211,21 @@ merge_range_partitions(variadic partitions REGCLASS[])
208211
Merge several adjacent RANGE partitions. Partitions are automatically ordered by increasing bounds; all the data will be accumulated in the first partition.
209212

210213
```plpgsql
211-
append_range_partition(parent REGCLASS,
214+
append_range_partition(parent_relid REGCLASS,
212215
partition_name TEXT DEFAULT NULL,
213216
tablespace TEXT DEFAULT NULL)
214217
```
215218
Append new RANGE partition with `pathman_config.range_interval` as interval.
216219

217220
```plpgsql
218-
prepend_range_partition(parent REGCLASS,
221+
prepend_range_partition(parent_relid REGCLASS,
219222
partition_name TEXT DEFAULT NULL,
220223
tablespace TEXT DEFAULT NULL)
221224
```
222225
Prepend new RANGE partition with `pathman_config.range_interval` as interval.
223226

224227
```plpgsql
225-
add_range_partition(relation REGCLASS,
228+
add_range_partition(parent_relid REGCLASS,
226229
start_value ANYELEMENT,
227230
end_value ANYELEMENT,
228231
partition_name TEXT DEFAULT NULL,
@@ -236,26 +239,26 @@ drop_range_partition(partition TEXT, delete_data BOOLEAN DEFAULT TRUE)
236239
Drop RANGE partition and all of its data if `delete_data` is true.
237240

238241
```plpgsql
239-
attach_range_partition(relation REGCLASS,
240-
partition REGCLASS,
241-
start_value ANYELEMENT,
242-
end_value ANYELEMENT)
242+
attach_range_partition(parent_relid REGCLASS,
243+
partition_relid REGCLASS,
244+
start_value ANYELEMENT,
245+
end_value ANYELEMENT)
243246
```
244247
Attach partition to the existing RANGE-partitioned relation. The attached table must have exactly the same structure as the parent table, including the dropped columns. Partition creation callback is invoked if set (see `pathman_config_params`).
245248

246249
```plpgsql
247-
detach_range_partition(partition REGCLASS)
250+
detach_range_partition(partition_relid REGCLASS)
248251
```
249252
Detach partition from the existing RANGE-partitioned relation.
250253

251254
```plpgsql
252-
disable_pathman_for(relation TEXT)
255+
disable_pathman_for(parent_relid REGCLASS)
253256
```
254257
Permanently disable `pg_pathman` partitioning mechanism for the specified parent table and remove the insert trigger if it exists. All partitions and data remain unchanged.
255258

256259
```plpgsql
257-
drop_partitions(parent REGCLASS,
258-
delete_data BOOLEAN DEFAULT FALSE)
260+
drop_partitions(parent_relid REGCLASS,
261+
delete_data BOOLEAN DEFAULT FALSE)
259262
```
260263
Drop partitions of the `parent` table (both foreign and local relations). If `delete_data` is `false`, the data is copied to the parent table first. Default is `false`.
261264

@@ -347,7 +350,7 @@ CREATE TABLE IF NOT EXISTS pathman_config_params (
347350
partrel REGCLASS NOT NULL PRIMARY KEY,
348351
enable_parent BOOLEAN NOT NULL DEFAULT TRUE,
349352
auto BOOLEAN NOT NULL DEFAULT TRUE,
350-
init_callback REGPROCEDURE NOT NULL DEFAULT 0,
353+
init_callback TEXT DEFAULT NULL,
351354
spawn_using_bgw BOOLEAN NOT NULL DEFAULT FALSE);
352355
```
353356
This table stores optional parameters which override standard behavior.
@@ -414,6 +417,7 @@ Shows memory consumption of various caches.
414417
- `RuntimeAppend` (overrides `Append` plan node)
415418
- `RuntimeMergeAppend` (overrides `MergeAppend` plan node)
416419
- `PartitionFilter` (drop-in replacement for INSERT triggers)
420+
- `PartitionRouter` (implements cross-partition UPDATEs)
417421

418422
`PartitionFilter` acts as a *proxy node* for INSERT's child scan, which means it can redirect output tuples to the corresponding partition:
419423

@@ -430,6 +434,22 @@ SELECT generate_series(1, 10), random();
430434
(4 rows)
431435
```
432436

437+
`PartitionRouter` is another *proxy node* used in conjunction with `PartitionFilter` to enable cross-partition UPDATEs (i.e. when you update any column of a partitioning key). Since this node has a great deal of side effects (ordinary `UPDATE` becomes slower; cross-partition `UPDATE` is transformed into `DELETE + INSERT`), it is disabled by default. To enable it, refer to the list of [GUCs](#disabling-pg_pathman) below.
438+
439+
```plpgsql
440+
EXPLAIN (COSTS OFF)
441+
UPDATE partitioned_table
442+
SET value = value + 1 WHERE value = 2;
443+
QUERY PLAN
444+
---------------------------------------------------
445+
Update on partitioned_table_0
446+
-> Custom Scan (PartitionRouter)
447+
-> Custom Scan (PartitionFilter)
448+
-> Seq Scan on partitioned_table_0
449+
Filter: (value = 2)
450+
(5 rows)
451+
```
452+
433453
`RuntimeAppend` and `RuntimeMergeAppend` have much in common: they come in handy in a case when WHERE condition takes form of:
434454
```
435455
VARIABLE OP PARAM
@@ -580,7 +600,7 @@ NOTICE: 100 rows copied from part_test_2
580600
(3 rows)
581601
```
582602

583-
- You can turn foreign tables into partitions using the `attach_range_partition()` function. Rows that were meant to be inserted into parent will be redirected to foreign partitions (as usual, PartitionFilter will be involved), though by default it is prohibited to insert rows into partitions provided not by `postgres_fdw`. Only superuser is allowed to set `pg_pathman.insert_into_fdw` GUC variable.
603+
- You can turn foreign tables into partitions using the `attach_range_partition()` function. Rows that were meant to be inserted into parent will be redirected to foreign partitions (as usual, PartitionFilter will be involved), though by default it is prohibited to insert rows into partitions provided not by `postgres_fdw`. Only superuser is allowed to set `pg_pathman.insert_into_fdw` [GUC](#disabling-pg_pathman) variable.
584604

585605
### HASH partitioning
586606
Consider an example of HASH partitioning. First create a table with some integer column:
@@ -710,7 +730,8 @@ There are several user-accessible [GUC](https://www.postgresql.org/docs/9.5/stat
710730
- `pg_pathman.enable` --- disable (or enable) `pg_pathman` **completely**
711731
- `pg_pathman.enable_runtimeappend` --- toggle `RuntimeAppend` custom node on\off
712732
- `pg_pathman.enable_runtimemergeappend` --- toggle `RuntimeMergeAppend` custom node on\off
713-
- `pg_pathman.enable_partitionfilter` --- toggle `PartitionFilter` custom node on\off
733+
- `pg_pathman.enable_partitionfilter` --- toggle `PartitionFilter` custom node on\off (for INSERTs)
734+
- `pg_pathman.enable_partitionrouter` --- toggle `PartitionRouter` custom node on\off (for cross-partition UPDATEs)
714735
- `pg_pathman.enable_auto_partition` --- toggle automatic partition creation on\off (per session)
715736
- `pg_pathman.enable_bounds_cache` --- toggle bounds cache on\off (faster updates of partitioning scheme)
716737
- `pg_pathman.insert_into_fdw` --- allow INSERTs into various FDWs `(disabled | postgres | any_fdw)`

0 commit comments

Comments
 (0)