22SET search_path = 'public';
33CREATE EXTENSION pg_pathman;
44CREATE 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+ */
617CREATE TABLE test_exprs.hash_rel (
718idSERIAL PRIMARY KEY,
819valueINTEGER,
@@ -18,9 +29,20 @@ SELECT COUNT(*) FROM test_exprs.hash_rel;
1829
1930SELECT create_hash_partitions('test_exprs.hash_rel', 'random()', 4);
2031ERROR: 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+
2143\set VERBOSITY default
2244SELECT 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)))
2446DETAIL: syntax error at or near ")"
2547QUERY: SELECT public.validate_expression(parent_relid, expression)
2648CONTEXT: 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,
2951 partition_data)"
3052PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
3153SELECT 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)
3355DETAIL: column "value3" does not exist
3456HINT: Perhaps you meant to reference the column "hash_rel.value" or the column "hash_rel.value2".
3557QUERY: SELECT public.validate_expression(parent_relid, expression)
@@ -38,6 +60,17 @@ SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
3860 expression,
3961 partition_data)"
4062PL/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+
4174\set VERBOSITY terse
4275SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value2', 4);
4376 create_hash_partitions
@@ -93,7 +126,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM test_exprs.hash_rel WHERE (value * value2) = 5
93126 Filter: ((value * value2) = 5)
94127(3 rows)
95128
96- /* range */
129+ /*
130+ * Test RANGE
131+ */
97132CREATE TABLE test_exprs.range_rel (id SERIAL PRIMARY KEY, dt TIMESTAMP, txt TEXT);
98133INSERT INTO test_exprs.range_rel (dt, txt)
99134SELECT 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;
174209(1 row)
175210
176211DROP SCHEMA test_exprs CASCADE;
177- NOTICE: drop cascades to17 other objects
212+ NOTICE: drop cascades to24 other objects
178213DROP EXTENSION pg_pathman;