Skip to content

Commit f1861df

Browse files
committed
Merge commit '6f2eb101a8edd21b50a57d5f9bb1076f27e302c8' into PGPRO9_6_pathman
2 parents d1ad3c6 + 6f2eb10 commit f1861df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4924
-5987
lines changed

contrib/pg_pathman/.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pg_pathman*.sql linguist-vendored=true
2+
*.h linguist-language=C
3+
*.c linguist-language=C
4+
*.spec linguist-vendored=true

contrib/pg_pathman/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ regression.out
88
*.pyc
99
*.gcda
1010
*.gcno
11-
pg_pathman--1.2.sql
11+
*.gcov
12+
pg_pathman--*.sql

contrib/pg_pathman/.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ env:
2020
- PGVERSION=9.5 CHECK_CODE=false
2121

2222
script: bash ./travis/pg-travis-test.sh
23+
24+
after_success:
25+
- bash <(curl -s https://codecov.io/bash)

contrib/pg_pathman/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o \
99
src/partition_creation.o $(WIN32RES)
1010

1111
EXTENSION = pg_pathman
12-
EXTVERSION = 1.2
12+
EXTVERSION = 1.3
1313
DATA_built = pg_pathman--$(EXTVERSION).sql
14-
DATA = pg_pathman--1.0.sql \
15-
pg_pathman--1.0--1.1.sql \
16-
pg_pathman--1.1.sql \
17-
pg_pathman--1.1--1.2.sql
14+
DATA = pg_pathman--1.0--1.1.sql \
15+
pg_pathman--1.1--1.2.sql
1816
PGFILEDESC = "pg_pathman - partitioning tool"
1917

2018
REGRESS = pathman_basic \
19+
pathman_inserts \
2120
pathman_runtime_nodes \
2221
pathman_callbacks \
2322
pathman_domains \
2423
pathman_foreign_keys \
2524
pathman_permissions \
2625
pathman_rowmarks \
2726
pathman_utility_stmt_hooking \
28-
pathman_calamity
27+
pathman_calamity \
28+
pathman_interval
2929
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
3030
EXTRA_CLEAN = pg_pathman--$(EXTVERSION).sql ./isolation_output
3131

contrib/pg_pathman/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ create_range_partitions(relation REGCLASS,
103103
p_count INTEGER DEFAULT NULL,
104104
partition_data BOOLEAN DEFAULT TRUE)
105105
```
106-
Performs RANGE partitioning for `relation` by partitioning key `attribute`. `start_value` argument specifies initial value, `interval` sets the range of values in a single partition, `count` is the number of premade partitions (if not set then pathman tries to determine it based on attribute values). Partition creation callback is invoked for each partition if set beforehand.
106+
Performs RANGE partitioning for `relation` by partitioning key `attribute`, `start_value` argument specifies initial value, `p_interval` sets the default range for auto created partitions or partitions created with `append_range_partition()` or `prepend_range_partition()` (if `NULL` then auto partition creation feature won't work), `p_count` is the number of premade partitions (if not set then `pg_pathman` tries to determine it based on attribute values). Partition creation callback is invoked for each partition if set beforehand.
107107

108108
```plpgsql
109109
create_partitions_from_range(relation REGCLASS,
@@ -167,6 +167,11 @@ merge_range_partitions(partition1 REGCLASS, partition2 REGCLASS)
167167
```
168168
Merge two adjacent RANGE partitions. First, data from `partition2` is copied to `partition1`, then `partition2` is removed.
169169

170+
```plpgsql
171+
merge_range_partitions(partitions REGCLASS[])
172+
```
173+
Merge several adjacent RANGE partitions (partitions must be specified in ascending or descending order). All the data will be accumulated in the first partition.
174+
170175
```plpgsql
171176
append_range_partition(parent REGCLASS,
172177
partition_name TEXT DEFAULT NULL,
@@ -188,7 +193,7 @@ add_range_partition(relation REGCLASS,
188193
partition_name TEXT DEFAULT NULL,
189194
tablespace TEXT DEFAULT NULL)
190195
```
191-
Create new RANGE partition for `relation` with specified range bounds.
196+
Create new RANGE partition for `relation` with specified range bounds. If `start_value` or `end_value` are NULL then corresponding range bound will be infinite.
192197

193198
```plpgsql
194199
drop_range_partition(partition TEXT, delete_data BOOLEAN DEFAULT TRUE)
@@ -222,6 +227,12 @@ Drop partitions of the `parent` table (both foreign and local relations). If `de
222227

223228
### Additional parameters
224229

230+
231+
```plpgsql
232+
set_interval(relation REGCLASS, value ANYELEMENT)
233+
```
234+
Update RANGE partitioned table interval. Note that interval must not be negative and it must not be trivial, i.e. its value should be greater than zero for numeric types, at least 1 microsecond for `TIMESTAMP` and at least 1 day for `DATE`.
235+
225236
```plpgsql
226237
set_enable_parent(relation REGCLASS, value BOOLEAN)
227238
```

contrib/pg_pathman/expected/pathman_basic.out

Lines changed: 155 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ UNION SELECT * FROM test.from_only_test;
494494
/* not ok, ONLY|non-ONLY in one query */
495495
EXPLAIN (COSTS OFF)
496496
SELECT * FROM test.from_only_test a JOIN ONLY test.from_only_test b USING(val);
497-
ERROR: It is prohibited to apply ONLY modifier to partitioned tables which have already been mentioned without ONLY
497+
ERROR: it is prohibited to apply ONLY modifier to partitioned tables which have already been mentioned without ONLY
498498
EXPLAIN (COSTS OFF)
499499
WITH q1 AS (SELECT * FROM test.from_only_test),
500500
q2 AS (SELECT * FROM ONLY test.from_only_test)
@@ -1409,6 +1409,35 @@ SELECT pathman.drop_range_partition('test.num_range_rel_7');
14091409
test.num_range_rel_7
14101410
(1 row)
14111411

1412+
SELECT pathman.drop_range_partition_expand_next('test.num_range_rel_4');
1413+
drop_range_partition_expand_next
1414+
----------------------------------
1415+
1416+
(1 row)
1417+
1418+
SELECT * FROM pathman.pathman_partition_list WHERE parent = 'test.num_range_rel'::regclass;
1419+
parent | partition | parttype | partattr | range_min | range_max
1420+
--------------------+----------------------+----------+----------+-----------+-----------
1421+
test.num_range_rel | test.num_range_rel_1 | 2 | id | 0 | 1000
1422+
test.num_range_rel | test.num_range_rel_2 | 2 | id | 1000 | 2000
1423+
test.num_range_rel | test.num_range_rel_3 | 2 | id | 2000 | 3000
1424+
test.num_range_rel | test.num_range_rel_6 | 2 | id | 3000 | 5000
1425+
(4 rows)
1426+
1427+
SELECT pathman.drop_range_partition_expand_next('test.num_range_rel_6');
1428+
drop_range_partition_expand_next
1429+
----------------------------------
1430+
1431+
(1 row)
1432+
1433+
SELECT * FROM pathman.pathman_partition_list WHERE parent = 'test.num_range_rel'::regclass;
1434+
parent | partition | parttype | partattr | range_min | range_max
1435+
--------------------+----------------------+----------+----------+-----------+-----------
1436+
test.num_range_rel | test.num_range_rel_1 | 2 | id | 0 | 1000
1437+
test.num_range_rel | test.num_range_rel_2 | 2 | id | 1000 | 2000
1438+
test.num_range_rel | test.num_range_rel_3 | 2 | id | 2000 | 3000
1439+
(3 rows)
1440+
14121441
SELECT pathman.append_range_partition('test.range_rel');
14131442
append_range_partition
14141443
------------------------
@@ -1510,6 +1539,62 @@ CREATE TABLE test.range_rel_test2 (
15101539
dt TIMESTAMP);
15111540
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test2', '2013-01-01'::DATE, '2014-01-01'::DATE);
15121541
ERROR: partition must have the exact same structure as parent
1542+
/* Half open ranges */
1543+
SELECT pathman.add_range_partition('test.range_rel', NULL, '2014-12-01'::DATE, 'test.range_rel_minus_infinity');
1544+
add_range_partition
1545+
-------------------------------
1546+
test.range_rel_minus_infinity
1547+
(1 row)
1548+
1549+
SELECT pathman.add_range_partition('test.range_rel', '2015-06-01'::DATE, NULL, 'test.range_rel_plus_infinity');
1550+
add_range_partition
1551+
------------------------------
1552+
test.range_rel_plus_infinity
1553+
(1 row)
1554+
1555+
SELECT pathman.append_range_partition('test.range_rel');
1556+
ERROR: Cannot append partition because last partition's range is half open
1557+
SELECT pathman.prepend_range_partition('test.range_rel');
1558+
ERROR: Cannot prepend partition because first partition's range is half open
1559+
DROP TABLE test.range_rel_minus_infinity;
1560+
CREATE TABLE test.range_rel_minus_infinity (LIKE test.range_rel INCLUDING ALL);
1561+
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_minus_infinity', NULL, '2014-12-01'::DATE);
1562+
attach_range_partition
1563+
-------------------------------
1564+
test.range_rel_minus_infinity
1565+
(1 row)
1566+
1567+
SELECT * FROM pathman.pathman_partition_list WHERE parent = 'test.range_rel'::REGCLASS;
1568+
parent | partition | parttype | partattr | range_min | range_max
1569+
----------------+-------------------------------+----------+----------+--------------------------+--------------------------
1570+
test.range_rel | test.range_rel_minus_infinity | 2 | dt | NULL | Mon Dec 01 00:00:00 2014
1571+
test.range_rel | test.range_rel_8 | 2 | dt | Mon Dec 01 00:00:00 2014 | Thu Jan 01 00:00:00 2015
1572+
test.range_rel | test.range_rel_1 | 2 | dt | Thu Jan 01 00:00:00 2015 | Sun Feb 01 00:00:00 2015
1573+
test.range_rel | test.range_rel_2 | 2 | dt | Sun Feb 01 00:00:00 2015 | Sun Mar 01 00:00:00 2015
1574+
test.range_rel | test.range_rel_3 | 2 | dt | Sun Mar 01 00:00:00 2015 | Wed Apr 01 00:00:00 2015
1575+
test.range_rel | test.range_rel_4 | 2 | dt | Wed Apr 01 00:00:00 2015 | Fri May 01 00:00:00 2015
1576+
test.range_rel | test.range_rel_6 | 2 | dt | Fri May 01 00:00:00 2015 | Mon Jun 01 00:00:00 2015
1577+
test.range_rel | test.range_rel_plus_infinity | 2 | dt | Mon Jun 01 00:00:00 2015 | NULL
1578+
(8 rows)
1579+
1580+
INSERT INTO test.range_rel (dt) VALUES ('2012-06-15');
1581+
INSERT INTO test.range_rel (dt) VALUES ('2015-12-15');
1582+
EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt < '2015-01-01';
1583+
QUERY PLAN
1584+
--------------------------------------------
1585+
Append
1586+
-> Seq Scan on range_rel_minus_infinity
1587+
-> Seq Scan on range_rel_8
1588+
(3 rows)
1589+
1590+
EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt >= '2015-05-01';
1591+
QUERY PLAN
1592+
-------------------------------------------
1593+
Append
1594+
-> Seq Scan on range_rel_6
1595+
-> Seq Scan on range_rel_plus_infinity
1596+
(3 rows)
1597+
15131598
/*
15141599
* Zero partitions count and adding partitions with specified name
15151600
*/
@@ -1525,9 +1610,9 @@ NOTICE: sequence "zero_seq" does not exist, skipping
15251610
(1 row)
15261611

15271612
SELECT pathman.append_range_partition('test.zero', 'test.zero_0');
1528-
ERROR: cannot append to empty partitions set
1613+
ERROR: relation "zero" has no partitions
15291614
SELECT pathman.prepend_range_partition('test.zero', 'test.zero_1');
1530-
ERROR: cannot prepend to empty partitions set
1615+
ERROR: relation "zero" has no partitions
15311616
SELECT pathman.add_range_partition('test.zero', 50, 70, 'test.zero_50');
15321617
add_range_partition
15331618
---------------------
@@ -1655,20 +1740,18 @@ SELECT COUNT(*) FROM ONLY test.hash_rel;
16551740

16561741
DROP TABLE test.hash_rel CASCADE;
16571742
SELECT pathman.drop_partitions('test.num_range_rel');
1658-
NOTICE: drop cascades to 4 other objects
1743+
NOTICE: drop cascades to 3 other objects
16591744
NOTICE: 998 rows copied from test.num_range_rel_1
16601745
NOTICE: 1000 rows copied from test.num_range_rel_2
16611746
NOTICE: 1000 rows copied from test.num_range_rel_3
1662-
NOTICE: 2 rows copied from test.num_range_rel_4
1663-
NOTICE: 0 rows copied from test.num_range_rel_6
16641747
drop_partitions
16651748
-----------------
1666-
5
1749+
3
16671750
(1 row)
16681751

16691752
DROP TABLE test.num_range_rel CASCADE;
16701753
DROP TABLE test.range_rel CASCADE;
1671-
NOTICE: drop cascades to 7 other objects
1754+
NOTICE: drop cascades to 9 other objects
16721755
/* Test automatic partition creation */
16731756
CREATE TABLE test.range_rel (
16741757
id SERIAL PRIMARY KEY,
@@ -2309,7 +2392,70 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
23092392
Filter: (c1 < 2500)
23102393
(12 rows)
23112394

2395+
/* Test recursive CTE */
2396+
CREATE TABLE test.recursive_cte_test_tbl(id INT NOT NULL, name TEXT NOT NULL);
2397+
SELECT * FROM create_hash_partitions('test.recursive_cte_test_tbl', 'id', 2);
2398+
create_hash_partitions
2399+
------------------------
2400+
2
2401+
(1 row)
2402+
2403+
INSERT INTO test.recursive_cte_test_tbl (id, name) SELECT id, 'name'||id FROM generate_series(1,100) f(id);
2404+
INSERT INTO test.recursive_cte_test_tbl (id, name) SELECT id, 'name'||(id + 1) FROM generate_series(1,100) f(id);
2405+
INSERT INTO test.recursive_cte_test_tbl (id, name) SELECT id, 'name'||(id + 2) FROM generate_series(1,100) f(id);
2406+
SELECT * FROM test.recursive_cte_test_tbl WHERE id = 5;
2407+
id | name
2408+
----+-------
2409+
5 | name5
2410+
5 | name6
2411+
5 | name7
2412+
(3 rows)
2413+
2414+
WITH RECURSIVE test AS (
2415+
SELECT min(name) AS name
2416+
FROM test.recursive_cte_test_tbl
2417+
WHERE id = 5
2418+
UNION ALL
2419+
SELECT (SELECT min(name)
2420+
FROM test.recursive_cte_test_tbl
2421+
WHERE id = 5 AND name > test.name)
2422+
FROM test
2423+
WHERE name IS NOT NULL)
2424+
SELECT * FROM test;
2425+
name
2426+
-------
2427+
name5
2428+
name6
2429+
name7
2430+
2431+
(4 rows)
2432+
2433+
/* Test create_range_partitions() + relnames */
2434+
CREATE TABLE test.provided_part_names(id INT NOT NULL);
2435+
INSERT INTO test.provided_part_names SELECT generate_series(1, 10);
2436+
SELECT create_hash_partitions('test.provided_part_names', 'id', 2,
2437+
relnames := ARRAY[]::TEXT[]); /* not ok */
2438+
ERROR: size of array 'relnames' must be equal to 'partitions_count'
2439+
SELECT create_hash_partitions('test.provided_part_names', 'id', 2,
2440+
relnames := ARRAY['p1', 'p2']::TEXT[]); /* ok */
2441+
create_hash_partitions
2442+
------------------------
2443+
2
2444+
(1 row)
2445+
2446+
/* list partitions */
2447+
SELECT partition FROM pathman_partition_list
2448+
WHERE parent = 'test.provided_part_names'::REGCLASS
2449+
ORDER BY partition;
2450+
partition
2451+
-----------
2452+
p1
2453+
p2
2454+
(2 rows)
2455+
2456+
DROP TABLE test.provided_part_names CASCADE;
2457+
NOTICE: drop cascades to 2 other objects
23122458
DROP SCHEMA test CASCADE;
2313-
NOTICE: drop cascades to 51 other objects
2459+
NOTICE: drop cascades to 54 other objects
23142460
DROP EXTENSION pg_pathman CASCADE;
23152461
DROP SCHEMA pathman CASCADE;

0 commit comments

Comments
 (0)