@@ -10,7 +10,7 @@ INSERT INTO test.hash_rel VALUES (1, 1);
10
10
INSERT INTO test.hash_rel VALUES (2, 2);
11
11
INSERT INTO test.hash_rel VALUES (3, 3);
12
12
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
13
- ERROR: partitioning key ' value' must be NOT NULL
13
+ ERROR: partitioning key " value" must be NOT NULL
14
14
ALTER TABLE test.hash_rel ALTER COLUMN value SET NOT NULL;
15
15
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3, partition_data:=false);
16
16
create_hash_partitions
@@ -131,10 +131,10 @@ CREATE INDEX ON test.range_rel (dt);
131
131
INSERT INTO test.range_rel (dt, txt)
132
132
SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2015-04-30', '1 day'::interval) as g;
133
133
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
134
- ERROR: partitioning key 'dt' must be NOT NULL
134
+ ERROR: partitioning key "dt" must be NOT NULL
135
135
ALTER TABLE test.range_rel ALTER COLUMN dt SET NOT NULL;
136
136
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
137
- ERROR: not enough partitions to fit all values of 'dt'
137
+ ERROR: not enough partitions to fit all values of "dt"
138
138
SELECT pathman.create_range_partitions('test.range_rel', 'DT', '2015-01-01'::DATE, '1 month'::INTERVAL);
139
139
NOTICE: sequence "range_rel_seq" does not exist, skipping
140
140
create_range_partitions
@@ -1080,6 +1080,64 @@ WHERE j1.dt < '2015-03-01' AND j2.dt >= '2015-02-01' ORDER BY j2.dt;
1080
1080
-> Index Scan using range_rel_2_pkey on range_rel_2 j1_1
1081
1081
(20 rows)
1082
1082
1083
+ /*
1084
+ * Test inlined SQL functions
1085
+ */
1086
+ CREATE TABLE test.sql_inline (id INT NOT NULL);
1087
+ SELECT pathman.create_hash_partitions('test.sql_inline', 'id', 3);
1088
+ create_hash_partitions
1089
+ ------------------------
1090
+ 3
1091
+ (1 row)
1092
+
1093
+ CREATE OR REPLACE FUNCTION test.sql_inline_func(i_id int) RETURNS SETOF INT AS $$
1094
+ select * from test.sql_inline where id = i_id limit 1;
1095
+ $$ LANGUAGE sql STABLE;
1096
+ EXPLAIN (COSTS OFF) SELECT * FROM test.sql_inline_func(5);
1097
+ QUERY PLAN
1098
+ --------------------------------------
1099
+ Limit
1100
+ -> Append
1101
+ -> Seq Scan on sql_inline_0
1102
+ Filter: (id = 5)
1103
+ (4 rows)
1104
+
1105
+ EXPLAIN (COSTS OFF) SELECT * FROM test.sql_inline_func(1);
1106
+ QUERY PLAN
1107
+ --------------------------------------
1108
+ Limit
1109
+ -> Append
1110
+ -> Seq Scan on sql_inline_2
1111
+ Filter: (id = 1)
1112
+ (4 rows)
1113
+
1114
+ DROP FUNCTION test.sql_inline_func(int);
1115
+ DROP TABLE test.sql_inline CASCADE;
1116
+ NOTICE: drop cascades to 3 other objects
1117
+ /*
1118
+ * Test by @baiyinqiqi (issue #60)
1119
+ */
1120
+ CREATE TABLE test.hash_varchar(val VARCHAR(40) NOT NULL);
1121
+ INSERT INTO test.hash_varchar SELECT generate_series(1, 20);
1122
+ SELECT pathman.create_hash_partitions('test.hash_varchar', 'val', 4);
1123
+ create_hash_partitions
1124
+ ------------------------
1125
+ 4
1126
+ (1 row)
1127
+
1128
+ SELECT * FROM test.hash_varchar WHERE val = 'a';
1129
+ val
1130
+ -----
1131
+ (0 rows)
1132
+
1133
+ SELECT * FROM test.hash_varchar WHERE val = '12'::TEXT;
1134
+ val
1135
+ -----
1136
+ 12
1137
+ (1 row)
1138
+
1139
+ DROP TABLE test.hash_varchar CASCADE;
1140
+ NOTICE: drop cascades to 4 other objects
1083
1141
/*
1084
1142
* Test CTE query
1085
1143
*/
@@ -1563,14 +1621,64 @@ SELECT * FROM test.hash_rel WHERE id = 123;
1563
1621
123 | 456 | 789
1564
1622
(1 row)
1565
1623
1624
+ /* Test replacing hash partition */
1625
+ CREATE TABLE test.hash_rel_extern (LIKE test.hash_rel INCLUDING ALL);
1626
+ SELECT pathman.replace_hash_partition('test.hash_rel_0', 'test.hash_rel_extern');
1627
+ replace_hash_partition
1628
+ ------------------------
1629
+ test.hash_rel_extern
1630
+ (1 row)
1631
+
1632
+ \d+ test.hash_rel_0
1633
+ Table "test.hash_rel_0"
1634
+ Column | Type | Modifiers | Storage | Stats target | Description
1635
+ --------+---------+------------------------------------------------------------+---------+--------------+-------------
1636
+ id | integer | not null default nextval('test.hash_rel_id_seq'::regclass) | plain | |
1637
+ value | integer | not null | plain | |
1638
+ abc | integer | | plain | |
1639
+ Indexes:
1640
+ "hash_rel_0_pkey" PRIMARY KEY, btree (id)
1641
+ Triggers:
1642
+ hash_rel_upd_trig BEFORE UPDATE ON test.hash_rel_0 FOR EACH ROW EXECUTE PROCEDURE test.hash_rel_upd_trig_func()
1643
+
1644
+ \d+ test.hash_rel_extern
1645
+ Table "test.hash_rel_extern"
1646
+ Column | Type | Modifiers | Storage | Stats target | Description
1647
+ --------+---------+------------------------------------------------------------+---------+--------------+-------------
1648
+ id | integer | not null default nextval('test.hash_rel_id_seq'::regclass) | plain | |
1649
+ value | integer | not null | plain | |
1650
+ abc | integer | | plain | |
1651
+ Indexes:
1652
+ "hash_rel_extern_pkey" PRIMARY KEY, btree (id)
1653
+ Check constraints:
1654
+ "pathman_hash_rel_extern_2_check" CHECK (pathman.get_hash_part_idx(hashint4(value), 3) = 0)
1655
+ Inherits: test.hash_rel
1656
+
1657
+ INSERT INTO test.hash_rel SELECT * FROM test.hash_rel_0;
1658
+ DROP TABLE test.hash_rel_0;
1659
+ /* Table with which we are replacing partition must have exact same structure */
1660
+ CREATE TABLE test.hash_rel_wrong(
1661
+ id INTEGER NOT NULL,
1662
+ value INTEGER);
1663
+ SELECT pathman.replace_hash_partition('test.hash_rel_1', 'test.hash_rel_wrong');
1664
+ ERROR: partition must have the exact same structure as parent
1665
+ EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
1666
+ QUERY PLAN
1667
+ -----------------------------------
1668
+ Append
1669
+ -> Seq Scan on hash_rel_extern
1670
+ -> Seq Scan on hash_rel_1
1671
+ -> Seq Scan on hash_rel_2
1672
+ (4 rows)
1673
+
1566
1674
/*
1567
1675
* Clean up
1568
1676
*/
1569
1677
SELECT pathman.drop_partitions('test.hash_rel');
1570
- NOTICE: drop cascades to 3 other objects
1571
- NOTICE: 2 rows copied from test.hash_rel_0
1678
+ NOTICE: drop cascades to 2 other objects
1572
1679
NOTICE: 3 rows copied from test.hash_rel_1
1573
1680
NOTICE: 2 rows copied from test.hash_rel_2
1681
+ NOTICE: 2 rows copied from test.hash_rel_extern
1574
1682
drop_partitions
1575
1683
-----------------
1576
1684
3
@@ -2191,31 +2299,31 @@ NOTICE: sequence "index_on_childs_seq" does not exist, skipping
2191
2299
0
2192
2300
(1 row)
2193
2301
2194
- SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1K ');
2302
+ SELECT add_range_partition('test.index_on_childs', 1, 1000, 'test.index_on_childs_1_1k ');
2195
2303
add_range_partition
2196
2304
---------------------------
2197
2305
test.index_on_childs_1_1k
2198
2306
(1 row)
2199
2307
2200
- SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1K_2K ');
2308
+ SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_1k_2k ');
2201
2309
append_range_partition
2202
2310
----------------------------
2203
2311
test.index_on_childs_1k_2k
2204
2312
(1 row)
2205
2313
2206
- SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2K_3K ');
2314
+ SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_2k_3k ');
2207
2315
append_range_partition
2208
2316
----------------------------
2209
2317
test.index_on_childs_2k_3k
2210
2318
(1 row)
2211
2319
2212
- SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3K_4K ');
2320
+ SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_3k_4k ');
2213
2321
append_range_partition
2214
2322
----------------------------
2215
2323
test.index_on_childs_3k_4k
2216
2324
(1 row)
2217
2325
2218
- SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4K_5K ');
2326
+ SELECT append_range_partition('test.index_on_childs', 'test.index_on_childs_4k_5k ');
2219
2327
append_range_partition
2220
2328
----------------------------
2221
2329
test.index_on_childs_4k_5k
@@ -2246,6 +2354,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
2246
2354
(12 rows)
2247
2355
2248
2356
DROP SCHEMA test CASCADE;
2249
- NOTICE: drop cascades to 50 other objects
2357
+ NOTICE: drop cascades to 51 other objects
2250
2358
DROP EXTENSION pg_pathman CASCADE;
2251
2359
DROP SCHEMA pathman CASCADE;
0 commit comments