@@ -494,7 +494,7 @@ UNION SELECT * FROM test.from_only_test;
494
494
/* not ok, ONLY|non-ONLY in one query */
495
495
EXPLAIN (COSTS OFF)
496
496
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
498
498
EXPLAIN (COSTS OFF)
499
499
WITH q1 AS (SELECT * FROM test.from_only_test),
500
500
q2 AS (SELECT * FROM ONLY test.from_only_test)
@@ -1409,6 +1409,35 @@ SELECT pathman.drop_range_partition('test.num_range_rel_7');
1409
1409
test.num_range_rel_7
1410
1410
(1 row)
1411
1411
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
+
1412
1441
SELECT pathman.append_range_partition('test.range_rel');
1413
1442
append_range_partition
1414
1443
------------------------
@@ -1510,6 +1539,62 @@ CREATE TABLE test.range_rel_test2 (
1510
1539
dt TIMESTAMP);
1511
1540
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test2', '2013-01-01'::DATE, '2014-01-01'::DATE);
1512
1541
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
+
1513
1598
/*
1514
1599
* Zero partitions count and adding partitions with specified name
1515
1600
*/
@@ -1525,9 +1610,9 @@ NOTICE: sequence "zero_seq" does not exist, skipping
1525
1610
(1 row)
1526
1611
1527
1612
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
1529
1614
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
1531
1616
SELECT pathman.add_range_partition('test.zero', 50, 70, 'test.zero_50');
1532
1617
add_range_partition
1533
1618
---------------------
@@ -1655,20 +1740,18 @@ SELECT COUNT(*) FROM ONLY test.hash_rel;
1655
1740
1656
1741
DROP TABLE test.hash_rel CASCADE;
1657
1742
SELECT pathman.drop_partitions('test.num_range_rel');
1658
- NOTICE: drop cascades to 4 other objects
1743
+ NOTICE: drop cascades to 3 other objects
1659
1744
NOTICE: 998 rows copied from test.num_range_rel_1
1660
1745
NOTICE: 1000 rows copied from test.num_range_rel_2
1661
1746
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
1664
1747
drop_partitions
1665
1748
-----------------
1666
- 5
1749
+ 3
1667
1750
(1 row)
1668
1751
1669
1752
DROP TABLE test.num_range_rel CASCADE;
1670
1753
DROP TABLE test.range_rel CASCADE;
1671
- NOTICE: drop cascades to 7 other objects
1754
+ NOTICE: drop cascades to 9 other objects
1672
1755
/* Test automatic partition creation */
1673
1756
CREATE TABLE test.range_rel (
1674
1757
id SERIAL PRIMARY KEY,
@@ -2309,7 +2392,70 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
2309
2392
Filter: (c1 < 2500)
2310
2393
(12 rows)
2311
2394
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
2312
2458
DROP SCHEMA test CASCADE;
2313
- NOTICE: drop cascades to 51 other objects
2459
+ NOTICE: drop cascades to 54 other objects
2314
2460
DROP EXTENSION pg_pathman CASCADE;
2315
2461
DROP SCHEMA pathman CASCADE;
0 commit comments