You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contrib/pg_pathman/README.md
+93-92Lines changed: 93 additions & 92 deletions
Original file line number
Diff line number
Diff line change
@@ -4,23 +4,17 @@ The `pg_pathman` module provides optimized partitioning mechanism and functions
4
4
5
5
##pg_pathman Concepts
6
6
7
-
Partitioning refers to splitting one large table into smaller pieces. Each row in such table assigns to a single partition based on partitioning key. Common partitioning strategies are:
8
-
9
-
* HASH - maps rows to partitions based on hash function values;
10
-
* RANGE - maps data to partitions based on ranges that you establish for each partition;
11
-
* LIST - maps data to partitions based on explicitly specified values of partitioning key for each partition.
12
-
13
-
PostgreSQL supports partitioning via table inheritance. Each partition must be created as child table with CHECK CONSTRAINT. For example:
7
+
Partitioning refers to splitting one large table into smaller pieces. Each row in such table assigns to a single partition based on partitioning key. PostgreSQL supports partitioning via table inheritance. Each partition must be created as child table with CHECK CONSTRAINT. For example:
14
8
15
9
```
16
10
CREATE TABLE test (id SERIAL PRIMARY KEY, title TEXT);
17
11
CREATE TABLE test_1 (CHECK ( id >= 100 AND id < 200 )) INHERITS (test);
18
12
CREATE TABLE test_2 (CHECK ( id >= 200 AND id < 300 )) INHERITS (test);
19
13
```
20
14
21
-
Despite the flexibilityofthis approachit has weakness. If query uses filteringtheoptimizer forcedto perform an exhaustive search and check constraints for each partition to determinepartitions fromwhichit shouldselect data. If the number of partitions is large the overhead may be significant.
15
+
Despite the flexibility this approachforcestheplannerto perform an exhaustive search and check constraints for each partition to determine whichone shouldpresent in the plan. If the number of partitions is large the overhead may be significant.
22
16
23
-
The`pg_pathman` module provides functions to manage partitions and partitioning mechanism optimized based on knowledge of the partitions structure. It stores partitioning configuration in the`pathman_config` table, each row of which contains single entry for partitioned table (relation name, partitioning key and type). During initialization the`pg_pathman` module caches information about child partitions in shared memory in form convenient to perform rapid search. Whenuser executesSELECT query pg_pathman analyzes conditions tree looking for conditions like:
17
+
The`pg_pathman` module provides functions to manage partitions and partitioning mechanism optimized based on knowledge of the partitions structure. It stores partitioning configuration in the`pathman_config` table, each row of which contains single entry for partitioned table (relation name, partitioning key and type). During initialization the`pg_pathman` module caches information about child partitions in shared memory in form convenient to perform rapid search. When SELECT queryexecutes`pg_pathman` analyzes conditions tree looking for conditions like:
24
18
25
19
```
26
20
VARIABLE OP CONST
@@ -31,7 +25,16 @@ where `VARIABLE` is partitioning key, `OP` is comparison operator (supported ope
31
25
WHERE id = 150
32
26
```
33
27
34
-
Based on partitioning type and operator the`pg_pathman` searches corresponding partitions and builds the plan.
28
+
Based on partitioning type and operator the`pg_pathman` searches corresponding partitions and builds the plan. Current version of`pg_pathman` supports two partitioning types:
29
+
30
+
* RANGE - maps data to partitions based on ranges of partitioning key. Optimization is achieved by using binary search algorithm.
31
+
* HASH - maps rows to partitions based on hash function values (only INTEGER attributes at the moment);
32
+
33
+
##Roadmap
34
+
35
+
* Optimize the execution of the NestedLoop join method;
36
+
* LIST-partitioning;
37
+
* HASH-partitioning for non integer attributes.
35
38
36
39
##Installation
37
40
@@ -155,120 +158,118 @@ Disables `pg_pathman` partitioning mechanism for the specified parent table and
155
158
###HASH
156
159
Consider an example of HASH partitioning. First create a table with some integer column:
157
160
```
158
-
CREATE TABLE hash_rel (
159
-
id SERIAL PRIMARY KEY,
160
-
value INTEGER);
161
-
INSERT INTO hash_rel (value) SELECT g FROM generate_series(1, 10000) as g;
161
+
CREATE TABLE items (
162
+
id SERIAL PRIMARY KEY,
163
+
name TEXT,
164
+
code BIGINT);
165
+
166
+
INSERT INTO items (id, name, code)
167
+
SELECT g, md5(g::text), random() * 100000
168
+
FROM generate_series(1, 100000) as g;
162
169
```
163
170
If partitions are supposed to have indexes, then they should be created for parent table before partitioning. In this case pg_pathman will automaticaly create indexes for partitions. Then run create_hash_partitions() function with appropriate arguments:
Here is an example of the query with filtering by partitioning key and its plan:
223
+
The first one creates partition with specified range. The second one creates partition with default interval and appends it to the partition list. It is also possible to attach an existing table as partition. For example we may want to attach an archive table (or even foreign table from another server) for outdated data:
224
+
215
225
```
216
-
SELECT * FROM range_rel WHERE dt >= '2012-04-30' AND dt <= '2012-05-01';
217
-
id | dt
218
-
-----+---------------------
219
-
851 | 2012-04-30 00:00:00
220
-
852 | 2012-05-01 00:00:00
226
+
CREATE FOREIGN TABLE journal_archive (
227
+
id INTEGER NOT NULL,
228
+
dt TIMESTAMP NOT NULL,
229
+
level INTEGER,
230
+
msg TEXT
231
+
) SERVER archive_server;
221
232
222
-
EXPLAIN SELECT * FROM range_rel WHERE dt >= '2012-04-30' AND dt <= '2012-05-01';
-> Seq Scan on journal_152 (cost=0.00..29.40 rows=0 width=0)
266
+
-> Seq Scan on journal_153 (cost=0.00..29.40 rows=0 width=0)
267
+
(3 rows)
261
268
```
262
-
Foreign table structure must exactly match the parent table.
263
269
264
-
In case when parent table is being dropped by DROP TABLE, you should invoke on_remove_partitions() function and delete particular entry from`pathman_config` table:
270
+
###Disable pg_pathman
271
+
To disable pg_pathman for some previously partitioned table use disable_partitioning() function: