Skip to content

Commit ee8c074

Browse files
committed
Merge branch 'rel_future_beta' into coveralls_support
2 parents 1256de7 + 66f4191 commit ee8c074

34 files changed

+2166
-677
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ REGRESS = pathman_basic \
2626
pathman_permissions \
2727
pathman_rowmarks \
2828
pathman_utility_stmt_hooking \
29-
pathman_calamity
29+
pathman_calamity \
30+
pathman_interval
3031
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
3132
EXTRA_CLEAN = pg_pathman--$(EXTVERSION).sql ./isolation_output
3233

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.
235+
225236
```plpgsql
226237
set_enable_parent(relation REGCLASS, value BOOLEAN)
227238
```

expected/pathman_basic.out

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

expected/pathman_calamity.out

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ SELECT count(*) FROM calamity.part_test;
100100
(1 row)
101101

102102
DELETE FROM calamity.part_test;
103+
/* test function create_hash_partitions() */
104+
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
105+
relnames := ARRAY['calamity.p1']::TEXT[]);
106+
ERROR: size of array 'relnames' must be equal to 'partitions_count'
107+
SELECT create_hash_partitions('calamity.part_test', 'val', 2,
108+
tablespaces := ARRAY['abcd']::TEXT[]);
109+
ERROR: size of array 'tablespaces' must be equal to 'partitions_count'
103110
/* test stub 'enable_parent' value for PATHMAN_CONFIG_PARAMS */
104111
INSERT INTO calamity.part_test SELECT generate_series(1, 30);
105112
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
@@ -132,6 +139,34 @@ NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
132139
4
133140
(1 row)
134141

142+
DELETE FROM calamity.part_test;
143+
/* check function validate_interval_value() */
144+
SELECT set_interval('pg_catalog.pg_class', 100); /* not ok */
145+
ERROR: table "pg_class" is not partitioned by RANGE
146+
INSERT INTO calamity.part_test SELECT generate_series(1, 30);
147+
SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
148+
create_range_partitions
149+
-------------------------
150+
3
151+
(1 row)
152+
153+
SELECT set_interval('calamity.part_test', 100); /* ok */
154+
set_interval
155+
--------------
156+
157+
(1 row)
158+
159+
SELECT set_interval('calamity.part_test', 15.6); /* not ok */
160+
ERROR: invalid input syntax for integer: "15.6"
161+
SELECT set_interval('calamity.part_test', 'abc'::text); /* not ok */
162+
ERROR: invalid input syntax for integer: "abc"
163+
SELECT drop_partitions('calamity.part_test', true);
164+
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
165+
drop_partitions
166+
-----------------
167+
3
168+
(1 row)
169+
135170
DELETE FROM calamity.part_test;
136171
/* check function build_hash_condition() */
137172
SELECT build_hash_condition('int4', 'val', 10, 1);
@@ -159,16 +194,22 @@ SELECT build_hash_condition('text', 'val', 10, NULL) IS NULL;
159194
SELECT build_hash_condition('calamity.part_test', 'val', 10, 1);
160195
ERROR: no hash function for type calamity.part_test
161196
/* check function build_range_condition() */
162-
SELECT build_range_condition('val', 10, 20);
163-
build_range_condition
164-
----------------------------
165-
val >= '10' AND val < '20'
197+
SELECT build_range_condition('calamity.part_test', 'val', 10, 20);
198+
build_range_condition
199+
------------------------------
200+
((val >= 10) AND (val < 20))
166201
(1 row)
167202

168-
SELECT build_range_condition('val', 10, NULL) IS NULL;
169-
?column?
170-
----------
171-
t
203+
SELECT build_range_condition('calamity.part_test', 'val', 10, NULL);
204+
build_range_condition
205+
-----------------------
206+
((val >= 10))
207+
(1 row)
208+
209+
SELECT build_range_condition('calamity.part_test', 'val', NULL, 10);
210+
build_range_condition
211+
-----------------------
212+
((val < 10))
172213
(1 row)
173214

174215
/* check function validate_relname() */
@@ -224,26 +265,12 @@ SELECT get_base_type(NULL) IS NULL;
224265
t
225266
(1 row)
226267

227-
/* check function get_attribute_type() */
228-
SELECT get_attribute_type('calamity.part_test', 'val');
229-
get_attribute_type
230-
--------------------
231-
integer
232-
(1 row)
233-
234-
SELECT get_attribute_type('calamity.part_test', NULL) IS NULL;
235-
?column?
236-
----------
237-
t
238-
(1 row)
239-
240-
SELECT get_attribute_type(NULL, 'val') IS NULL;
241-
?column?
242-
----------
243-
t
244-
(1 row)
245-
246-
SELECT get_attribute_type(NULL, NULL) IS NULL;
268+
/* check function get_partition_key_type() */
269+
SELECT get_partition_key_type('calamity.part_test');
270+
ERROR: relation "part_test" has no partitions
271+
SELECT get_partition_key_type(0::regclass);
272+
ERROR: relation "0" has no partitions
273+
SELECT get_partition_key_type(NULL) IS NULL;
247274
?column?
248275
----------
249276
t
@@ -328,6 +355,15 @@ SELECT build_update_trigger_func_name(NULL) IS NULL;
328355
/* check function stop_concurrent_part_task() */
329356
SELECT stop_concurrent_part_task(1::regclass);
330357
ERROR: cannot find worker for relation "1"
358+
/* check function drop_range_partition_expand_next() */
359+
SELECT drop_range_partition_expand_next('pg_class');
360+
ERROR: relation "pg_class" is not a partition
361+
SELECT drop_range_partition_expand_next(NULL) IS NULL;
362+
?column?
363+
----------
364+
t
365+
(1 row)
366+
331367
/* check invoke_on_partition_created_callback() for RANGE */
332368
SELECT invoke_on_partition_created_callback('calamity.part_test', 'calamity.part_test', 1, NULL, NULL::int);
333369
ERROR: both bounds must be provided for RANGE partition
@@ -416,22 +452,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_ok; /* check that pathman is ena
416452
-> Seq Scan on part_ok_3
417453
(5 rows)
418454

419-
ALTER TABLE calamity.wrong_partition
420-
ADD CONSTRAINT pathman_wrong_partition_1_check
421-
CHECK (val < 10); /* wrong constraint */
422-
SELECT add_to_pathman_config('calamity.part_test', 'val', '10');
423-
ERROR: wrong constraint format for RANGE partition "wrong_partition"
424-
EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_ok; /* check that pathman is enabled */
425-
QUERY PLAN
426-
-----------------------------
427-
Append
428-
-> Seq Scan on part_ok_0
429-
-> Seq Scan on part_ok_1
430-
-> Seq Scan on part_ok_2
431-
-> Seq Scan on part_ok_3
432-
(5 rows)
433-
434-
ALTER TABLE calamity.wrong_partition DROP CONSTRAINT pathman_wrong_partition_1_check;
435455
ALTER TABLE calamity.wrong_partition
436456
ADD CONSTRAINT pathman_wrong_partition_1_check
437457
CHECK (val = 1 OR val = 2); /* wrong constraint */

0 commit comments

Comments
 (0)