2
2
SET search_path = 'public';
3
3
CREATE EXTENSION pg_pathman;
4
4
CREATE SCHEMA test_exprs;
5
- /* hash */
5
+ /* We use this rel to check 'pathman_hooks_enabled' */
6
+ CREATE TABLE test_exprs.canary(val INT4 NOT NULL);
7
+ CREATE TABLE test_exprs.canary_copy (LIKE test_exprs.canary);
8
+ SELECT create_hash_partitions('test_exprs.canary', 'val', 5);
9
+ create_hash_partitions
10
+ ------------------------
11
+ 5
12
+ (1 row)
13
+
14
+ /*
15
+ * Test HASH
16
+ */
6
17
CREATE TABLE test_exprs.hash_rel (
7
18
idSERIAL PRIMARY KEY,
8
19
valueINTEGER,
@@ -18,9 +29,20 @@ SELECT COUNT(*) FROM test_exprs.hash_rel;
18
29
19
30
SELECT create_hash_partitions('test_exprs.hash_rel', 'random()', 4);
20
31
ERROR: functions in partitioning expression must be marked IMMUTABLE
32
+ /* Check that 'pathman_hooks_enabled' is true (1 partition in plan) */
33
+ EXPLAIN (COSTS OFF) INSERT INTO test_exprs.canary_copy
34
+ SELECT * FROM test_exprs.canary WHERE val = 1;
35
+ QUERY PLAN
36
+ ----------------------------------
37
+ Insert on canary_copy
38
+ -> Append
39
+ -> Seq Scan on canary_0
40
+ Filter: (val = 1)
41
+ (4 rows)
42
+
21
43
\set VERBOSITY default
22
44
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value2))', 4);
23
- ERROR: failed to parse partitioning expression
45
+ ERROR: failed to parse partitioning expression (value * value2)))
24
46
DETAIL: syntax error at or near ")"
25
47
QUERY: SELECT public.validate_expression(parent_relid, expression)
26
48
CONTEXT: PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
@@ -29,7 +51,7 @@ SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
29
51
partition_data)"
30
52
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
31
53
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value3', 4);
32
- ERROR: failed to analyze partitioning expression
54
+ ERROR: failed to analyze partitioning expression (value * value3)
33
55
DETAIL: column "value3" does not exist
34
56
HINT: Perhaps you meant to reference the column "hash_rel.value" or the column "hash_rel.value2".
35
57
QUERY: SELECT public.validate_expression(parent_relid, expression)
@@ -38,6 +60,17 @@ SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
38
60
expression,
39
61
partition_data)"
40
62
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
63
+ /* Check that 'pathman_hooks_enabled' is true (1 partition in plan) */
64
+ EXPLAIN (COSTS OFF) INSERT INTO test_exprs.canary_copy
65
+ SELECT * FROM test_exprs.canary WHERE val = 1;
66
+ QUERY PLAN
67
+ ----------------------------------
68
+ Insert on canary_copy
69
+ -> Append
70
+ -> Seq Scan on canary_0
71
+ Filter: (val = 1)
72
+ (4 rows)
73
+
41
74
\set VERBOSITY terse
42
75
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value2', 4);
43
76
create_hash_partitions
@@ -93,7 +126,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM test_exprs.hash_rel WHERE (value * value2) = 5
93
126
Filter: ((value * value2) = 5)
94
127
(3 rows)
95
128
96
- /* range */
129
+ /*
130
+ * Test RANGE
131
+ */
97
132
CREATE TABLE test_exprs.range_rel (id SERIAL PRIMARY KEY, dt TIMESTAMP, txt TEXT);
98
133
INSERT INTO test_exprs.range_rel (dt, txt)
99
134
SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2020-04-30', '1 month'::interval) as g;
@@ -174,5 +209,5 @@ SELECT COUNT(*) FROM test_exprs.range_rel_2;
174
209
(1 row)
175
210
176
211
DROP SCHEMA test_exprs CASCADE;
177
- NOTICE: drop cascades to17 other objects
212
+ NOTICE: drop cascades to24 other objects
178
213
DROP EXTENSION pg_pathman;