Skip to content

Commit 5531ce0

Browse files
committed
regression tests for half-open ranges
1 parent 9cbefb5 commit 5531ce0

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

expected/pathman_basic.out

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,62 @@ CREATE TABLE test.range_rel_test2 (
14521452
dt TIMESTAMP);
14531453
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test2', '2013-01-01'::DATE, '2014-01-01'::DATE);
14541454
ERROR: partition must have the exact same structure as parent
1455+
/* Half open ranges */
1456+
SELECT pathman.add_range_partition('test.range_rel', NULL, '2014-12-01'::DATE, 'test.range_rel_minus_infinity');
1457+
add_range_partition
1458+
-------------------------------
1459+
test.range_rel_minus_infinity
1460+
(1 row)
1461+
1462+
SELECT pathman.add_range_partition('test.range_rel', '2015-06-01'::DATE, NULL, 'test.range_rel_plus_infinity');
1463+
add_range_partition
1464+
------------------------------
1465+
test.range_rel_plus_infinity
1466+
(1 row)
1467+
1468+
SELECT pathman.append_range_partition('test.range_rel');
1469+
ERROR: Cannot append partition because last partition's range is half open
1470+
SELECT pathman.prepend_range_partition('test.range_rel');
1471+
ERROR: Cannot prepend partition because first partition's range is half open
1472+
DROP TABLE test.range_rel_minus_infinity;
1473+
CREATE TABLE test.range_rel_minus_infinity (LIKE test.range_rel INCLUDING ALL);
1474+
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_minus_infinity', NULL, '2014-12-01'::DATE);
1475+
attach_range_partition
1476+
-------------------------------
1477+
test.range_rel_minus_infinity
1478+
(1 row)
1479+
1480+
SELECT * FROM pathman.pathman_partition_list WHERE parent = 'test.range_rel'::REGCLASS;
1481+
parent | partition | parttype | partattr | range_min | range_max
1482+
----------------+-------------------------------+----------+----------+--------------------------+--------------------------
1483+
test.range_rel | test.range_rel_minus_infinity | 2 | dt | NULL | Mon Dec 01 00:00:00 2014
1484+
test.range_rel | test.range_rel_8 | 2 | dt | Mon Dec 01 00:00:00 2014 | Thu Jan 01 00:00:00 2015
1485+
test.range_rel | test.range_rel_1 | 2 | dt | Thu Jan 01 00:00:00 2015 | Sun Feb 01 00:00:00 2015
1486+
test.range_rel | test.range_rel_2 | 2 | dt | Sun Feb 01 00:00:00 2015 | Sun Mar 01 00:00:00 2015
1487+
test.range_rel | test.range_rel_3 | 2 | dt | Sun Mar 01 00:00:00 2015 | Wed Apr 01 00:00:00 2015
1488+
test.range_rel | test.range_rel_4 | 2 | dt | Wed Apr 01 00:00:00 2015 | Fri May 01 00:00:00 2015
1489+
test.range_rel | test.range_rel_6 | 2 | dt | Fri May 01 00:00:00 2015 | Mon Jun 01 00:00:00 2015
1490+
test.range_rel | test.range_rel_plus_infinity | 2 | dt | Mon Jun 01 00:00:00 2015 | NULL
1491+
(8 rows)
1492+
1493+
INSERT INTO test.range_rel (dt) VALUES ('2012-06-15');
1494+
INSERT INTO test.range_rel (dt) VALUES ('2015-12-15');
1495+
EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt < '2015-01-01';
1496+
QUERY PLAN
1497+
--------------------------------------------
1498+
Append
1499+
-> Seq Scan on range_rel_minus_infinity
1500+
-> Seq Scan on range_rel_8
1501+
(3 rows)
1502+
1503+
EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt >= '2015-05-01';
1504+
QUERY PLAN
1505+
-------------------------------------------
1506+
Append
1507+
-> Seq Scan on range_rel_6
1508+
-> Seq Scan on range_rel_plus_infinity
1509+
(3 rows)
1510+
14551511
/*
14561512
* Zero partitions count and adding partitions with specified name
14571513
*/
@@ -1560,7 +1616,7 @@ NOTICE: 0 rows copied from test.num_range_rel_6
15601616

15611617
DROP TABLE test.num_range_rel CASCADE;
15621618
DROP TABLE test.range_rel CASCADE;
1563-
NOTICE: drop cascades to 7 other objects
1619+
NOTICE: drop cascades to 9 other objects
15641620
/* Test automatic partition creation */
15651621
CREATE TABLE test.range_rel (
15661622
id SERIAL PRIMARY KEY,

range.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ BEGIN
765765
INTO p_range;
766766

767767
IF p_range[2] IS NULL THEN
768-
RAISE EXCEPTION 'Cannot append partition because last partition is half open';
768+
RAISE EXCEPTION 'Cannot append partition because last partition''s range is half open';
769769
END IF;
770770

771771
IF @extschema@.is_date_type(p_atttype) THEN
@@ -879,7 +879,7 @@ BEGIN
879879
INTO p_range;
880880

881881
IF p_range[1] IS NULL THEN
882-
RAISE EXCEPTION 'Cannot prepend partition because first partition is half open';
882+
RAISE EXCEPTION 'Cannot prepend partition because first partition''s range is half open';
883883
END IF;
884884

885885
IF @extschema@.is_date_type(p_atttype) THEN

sql/pathman_basic.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,20 @@ CREATE TABLE test.range_rel_test2 (
398398
dt TIMESTAMP);
399399
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test2', '2013-01-01'::DATE, '2014-01-01'::DATE);
400400

401+
/* Half open ranges */
402+
SELECT pathman.add_range_partition('test.range_rel', NULL, '2014-12-01'::DATE, 'test.range_rel_minus_infinity');
403+
SELECT pathman.add_range_partition('test.range_rel', '2015-06-01'::DATE, NULL, 'test.range_rel_plus_infinity');
404+
SELECT pathman.append_range_partition('test.range_rel');
405+
SELECT pathman.prepend_range_partition('test.range_rel');
406+
DROP TABLE test.range_rel_minus_infinity;
407+
CREATE TABLE test.range_rel_minus_infinity (LIKE test.range_rel INCLUDING ALL);
408+
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_minus_infinity', NULL, '2014-12-01'::DATE);
409+
SELECT * FROM pathman.pathman_partition_list WHERE parent = 'test.range_rel'::REGCLASS;
410+
INSERT INTO test.range_rel (dt) VALUES ('2012-06-15');
411+
INSERT INTO test.range_rel (dt) VALUES ('2015-12-15');
412+
EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt < '2015-01-01';
413+
EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt >= '2015-05-01';
414+
401415
/*
402416
* Zero partitions count and adding partitions with specified name
403417
*/

src/relation_info.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ typedef struct
5656

5757
/*
5858
* Comparison macros for bounds
59-
* If both bounds are minus infinite or plus infinite then they are equal.
60-
* Else call original comparison function.
6159
*/
6260
inline static int8_t
6361
cmp_bounds(FmgrInfo *cmp_func, const Bound *b1, const Bound *b2)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy