Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf19deb3

Browse files
committed
Merge with rel_future_beta branch
2 parents3b528e7 +8fa83bf commitf19deb3

11 files changed

+270
-98
lines changed

‎expected/pathman_basic.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,9 @@ SELECT pathman.create_partitions_from_range('test."RangeRel"', 'dt', '2015-01-01
15291529
DROP TABLE test."RangeRel" CASCADE;
15301530
NOTICE: drop cascades to 6 other objects
15311531
SELECT * FROM pathman.pathman_config;
1532-
partrel | expr | parttype | range_interval | cooked_expr
1533-
--------------------+------+----------+----------------+------------------------------------------------------------------------------------------------------------------------
1534-
test.num_range_rel | id | 2 | 1000 | {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location-1}
1532+
partrel | expr | parttype | range_interval | cooked_expr
1533+
--------------------+------+----------+----------------+-----------------------------------------------------------------------------------------------------------------------
1534+
test.num_range_rel | id | 2 | 1000 | {VAR :varno 1 :varattno 1 :vartype 23 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location8}
15351535
(1 row)
15361536

15371537
CREATE TABLE test."RangeRel" (

‎expected/pathman_calamity.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ ERROR: 'expression' should not be NULL
306306
SELECT validate_expression('calamity.part_test', 'valval');/* not ok */
307307
ERROR: cannot find type name for attribute "valval" of relation "part_test"
308308
SELECT validate_expression('calamity.part_test', 'random()');/* not ok */
309-
ERROR: failed to analyze partitioning expression(random())
309+
ERROR: failed to analyze partitioning expression"random()"
310310
SELECT validate_expression('calamity.part_test', 'val');/* OK */
311311
validate_expression
312312
---------------------

‎expected/pathman_expressions.out

Lines changed: 129 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,99 @@
22
SET search_path = 'public';
33
CREATE EXTENSION pg_pathman;
44
CREATE SCHEMA test_exprs;
5+
/*
6+
* Test partitioning expression canonicalization process
7+
*/
8+
CREATE TABLE test_exprs.canon(c JSONB NOT NULL);
9+
SELECT create_range_partitions('test_exprs.canon', '(C->>''key'')::int8', 1, 10, 2);
10+
create_range_partitions
11+
-------------------------
12+
2
13+
(1 row)
14+
15+
SELECT expr FROM pathman_config; /* check expression */
16+
expr
17+
-------------------------------
18+
((c ->> 'key'::text))::bigint
19+
(1 row)
20+
21+
INSERT INTO test_exprs.canon VALUES ('{ "key": 2, "value": 0 }');
22+
SELECT *, tableoid::REGCLASS FROM test_exprs.canon;
23+
c | tableoid
24+
------------------------+--------------------
25+
{"key": 2, "value": 0} | test_exprs.canon_1
26+
(1 row)
27+
28+
DROP TABLE test_exprs.canon CASCADE;
29+
NOTICE: drop cascades to 3 other objects
30+
CREATE TABLE test_exprs.canon(val TEXT NOT NULL);
31+
CREATE SEQUENCE test_exprs.canon_seq;
32+
SELECT add_to_pathman_config('test_exprs.canon', 'VAL collate "C"', NULL);
33+
add_to_pathman_config
34+
-----------------------
35+
t
36+
(1 row)
37+
38+
SELECT add_range_partition('test_exprs.canon', 'a'::TEXT, 'b');
39+
add_range_partition
40+
---------------------
41+
test_exprs.canon_1
42+
(1 row)
43+
44+
SELECT add_range_partition('test_exprs.canon', 'b'::TEXT, 'c');
45+
add_range_partition
46+
---------------------
47+
test_exprs.canon_2
48+
(1 row)
49+
50+
SELECT add_range_partition('test_exprs.canon', 'c'::TEXT, 'd');
51+
add_range_partition
52+
---------------------
53+
test_exprs.canon_3
54+
(1 row)
55+
56+
SELECT add_range_partition('test_exprs.canon', 'd'::TEXT, 'e');
57+
add_range_partition
58+
---------------------
59+
test_exprs.canon_4
60+
(1 row)
61+
62+
SELECT expr FROM pathman_config; /* check expression */
63+
expr
64+
-------------------
65+
(val COLLATE "C")
66+
(1 row)
67+
68+
INSERT INTO test_exprs.canon VALUES ('b');
69+
SELECT *, tableoid::REGCLASS FROM test_exprs.canon;
70+
val | tableoid
71+
-----+--------------------
72+
b | test_exprs.canon_2
73+
(1 row)
74+
75+
EXPLAIN (COSTS OFF) SELECT * FROM test_exprs.canon WHERE val COLLATE "C" < ALL (array['b', 'c']);
76+
QUERY PLAN
77+
---------------------------
78+
Append
79+
-> Seq Scan on canon_1
80+
(2 rows)
81+
82+
EXPLAIN (COSTS OFF) SELECT * FROM test_exprs.canon WHERE val COLLATE "POSIX" < ALL (array['b', 'c']);
83+
QUERY PLAN
84+
-----------------------------------------------------------
85+
Append
86+
-> Seq Scan on canon_1
87+
Filter: ((val)::text < 'b'::text COLLATE "POSIX")
88+
-> Seq Scan on canon_2
89+
Filter: ((val)::text < 'b'::text COLLATE "POSIX")
90+
-> Seq Scan on canon_3
91+
Filter: ((val)::text < 'b'::text COLLATE "POSIX")
92+
-> Seq Scan on canon_4
93+
Filter: ((val)::text < 'b'::text COLLATE "POSIX")
94+
(9 rows)
95+
96+
DROP TABLE test_exprs.canon CASCADE;
97+
NOTICE: drop cascades to 5 other objects
598
/* We use this rel to check 'pathman_hooks_enabled' */
699
CREATE TABLE test_exprs.canary(val INT4 NOT NULL);
7100
CREATE TABLE test_exprs.canary_copy (LIKE test_exprs.canary);
@@ -27,43 +120,52 @@ SELECT COUNT(*) FROM test_exprs.hash_rel;
27120
5
28121
(1 row)
29122

123+
\set VERBOSITY default
30124
/* Try using constant expression */
31125
SELECT create_hash_partitions('test_exprs.hash_rel', '1 + 1', 4);
32-
ERROR: partitioning expression should reference table "hash_rel"
33-
\set VERBOSITY default
126+
ERROR: failed to analyze partitioning expression "1 + 1"
127+
DETAIL: partitioning expression should reference table "hash_rel"
128+
CONTEXT: SQL statement "SELECT public.validate_expression(parent_relid, expression)"
129+
PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
130+
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
131+
expression,
132+
partition_data)"
133+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
134+
/* Try using multiple queries */
135+
SELECT create_hash_partitions('test_exprs.hash_rel',
136+
'value, (select oid from pg_class limit 1)',
137+
4);
138+
ERROR: failed to analyze partitioning expression "value, (select oid from pg_class limit 1)"
139+
DETAIL: subqueries are not allowed in partitioning expression
140+
CONTEXT: SQL statement "SELECT public.validate_expression(parent_relid, expression)"
141+
PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
142+
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
143+
expression,
144+
partition_data)"
145+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
34146
/* Try using mutable expression */
35147
SELECT create_hash_partitions('test_exprs.hash_rel', 'random()', 4);
36-
ERROR: failed to analyze partitioning expression(random())
148+
ERROR: failed to analyze partitioning expression"random()"
37149
DETAIL: functions in partitioning expression must be marked IMMUTABLE
38150
CONTEXT: SQL statement "SELECT public.validate_expression(parent_relid, expression)"
39151
PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
40152
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
41153
expression,
42154
partition_data)"
43155
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
44-
/* Check that 'pathman_hooks_enabled' is true (1 partition in plan) */
45-
EXPLAIN (COSTS OFF) INSERT INTO test_exprs.canary_copy
46-
SELECT * FROM test_exprs.canary WHERE val = 1;
47-
QUERY PLAN
48-
----------------------------------
49-
Insert on canary_copy
50-
-> Append
51-
-> Seq Scan on canary_0
52-
Filter: (val = 1)
53-
(4 rows)
54-
55-
/* Try using missing columns */
156+
/* Try using broken parentheses */
56157
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value2))', 4);
57-
ERROR: failed to parse partitioning expression(value * value2)))
158+
ERROR: failed to parse partitioning expression"value * value2))"
58159
DETAIL: syntax error at or near ")"
59160
QUERY: SELECT public.validate_expression(parent_relid, expression)
60161
CONTEXT: PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
61162
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
62163
expression,
63164
partition_data)"
64165
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
166+
/* Try using missing columns */
65167
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value3', 4);
66-
ERROR: failed to analyze partitioning expression(value * value3)
168+
ERROR: failed to analyze partitioning expression"value * value3"
67169
DETAIL: column "value3" does not exist
68170
HINT: Perhaps you meant to reference the column "hash_rel.value" or the column "hash_rel.value2".
69171
QUERY: SELECT public.validate_expression(parent_relid, expression)
@@ -144,15 +246,22 @@ EXPLAIN (COSTS OFF) SELECT * FROM test_exprs.hash_rel WHERE (value * value2) = 5
144246
CREATE TABLE test_exprs.range_rel (id SERIAL PRIMARY KEY, dt TIMESTAMP, txt TEXT);
145247
INSERT INTO test_exprs.range_rel (dt, txt)
146248
SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2020-04-30', '1 month'::interval) as g;
249+
\set VERBOSITY default
147250
/* Try using constant expression */
148251
SELECT create_range_partitions('test_exprs.range_rel', '''16 years''::interval',
149252
'15 years'::INTERVAL, '1 year'::INTERVAL, 10);
150-
ERROR: partitioning expression should reference table "range_rel"
151-
\set VERBOSITY default
253+
ERROR: failed to analyze partitioning expression "'16 years'::interval"
254+
DETAIL: partitioning expression should reference table "range_rel"
255+
CONTEXT: SQL statement "SELECT public.validate_expression(parent_relid, expression)"
256+
PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM
257+
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
258+
expression,
259+
partition_data)"
260+
PL/pgSQL function create_range_partitions(regclass,text,anyelement,interval,integer,boolean) line 12 at PERFORM
152261
/* Try using mutable expression */
153262
SELECT create_range_partitions('test_exprs.range_rel', 'RANDOM()',
154263
'15 years'::INTERVAL, '1 year'::INTERVAL, 10);
155-
ERROR: failed to analyze partitioning expression(RANDOM())
264+
ERROR: failed to analyze partitioning expression"RANDOM()"
156265
DETAIL: functions in partitioning expression must be marked IMMUTABLE
157266
CONTEXT: SQL statement "SELECT public.validate_expression(parent_relid, expression)"
158267
PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERFORM

‎range.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BEGIN
3636

3737
/* Check lower boundary*/
3838
IF start_value> min_value THEN
39-
RAISE EXCEPTION'start value isless than min value of "%"', expression;
39+
RAISE EXCEPTION'start value isgreater than min value of "%"', expression;
4040
END IF;
4141

4242
/* Check upper boundary*/

‎sql/pathman_expressions.sql

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ CREATE EXTENSION pg_pathman;
55
CREATESCHEMAtest_exprs;
66

77

8+
9+
/*
10+
* Test partitioning expression canonicalization process
11+
*/
12+
13+
CREATETABLEtest_exprs.canon(c JSONBNOT NULL);
14+
SELECT create_range_partitions('test_exprs.canon','(C->>''key'')::int8',1,10,2);
15+
SELECT exprFROM pathman_config;/* check expression*/
16+
INSERT INTOtest_exprs.canonVALUES ('{ "key": 2, "value": 0 }');
17+
SELECT*, tableoid::REGCLASSFROMtest_exprs.canon;
18+
DROPTABLEtest_exprs.canon CASCADE;
19+
20+
21+
CREATETABLEtest_exprs.canon(valTEXTNOT NULL);
22+
CREATESEQUENCEtest_exprs.canon_seq;
23+
SELECT add_to_pathman_config('test_exprs.canon','VAL collate "C"',NULL);
24+
SELECT add_range_partition('test_exprs.canon','a'::TEXT,'b');
25+
SELECT add_range_partition('test_exprs.canon','b'::TEXT,'c');
26+
SELECT add_range_partition('test_exprs.canon','c'::TEXT,'d');
27+
SELECT add_range_partition('test_exprs.canon','d'::TEXT,'e');
28+
SELECT exprFROM pathman_config;/* check expression*/
29+
INSERT INTOtest_exprs.canonVALUES ('b');
30+
SELECT*, tableoid::REGCLASSFROMtest_exprs.canon;
31+
EXPLAIN (COSTS OFF)SELECT*FROMtest_exprs.canonWHERE val COLLATE"C"< ALL (array['b','c']);
32+
EXPLAIN (COSTS OFF)SELECT*FROMtest_exprs.canonWHERE val COLLATE"POSIX"< ALL (array['b','c']);
33+
DROPTABLEtest_exprs.canon CASCADE;
34+
35+
36+
837
/* We use this rel to check 'pathman_hooks_enabled'*/
938
CREATETABLEtest_exprs.canary(val INT4NOT NULL);
1039
CREATETABLEtest_exprs.canary_copy (LIKEtest_exprs.canary);
@@ -27,21 +56,24 @@ INSERT INTO test_exprs.hash_rel (value, value2)
2756
SELECTCOUNT(*)FROMtest_exprs.hash_rel;
2857

2958

59+
60+
\set VERBOSITY default
61+
3062
/* Try using constant expression*/
3163
SELECT create_hash_partitions('test_exprs.hash_rel','1 + 1',4);
3264

33-
34-
\set VERBOSITY default
65+
/* Try using multiple queries*/
66+
SELECT create_hash_partitions('test_exprs.hash_rel',
67+
'value, (select oid from pg_class limit 1)',
68+
4);
3569

3670
/* Try using mutable expression*/
3771
SELECT create_hash_partitions('test_exprs.hash_rel','random()',4);
3872

39-
/* Check that 'pathman_hooks_enabled' is true (1 partition in plan)*/
40-
EXPLAIN (COSTS OFF)INSERT INTOtest_exprs.canary_copy
41-
SELECT*FROMtest_exprs.canaryWHERE val=1;
73+
/* Try using broken parentheses*/
74+
SELECT create_hash_partitions('test_exprs.hash_rel','value * value2))',4);
4275

4376
/* Try using missing columns*/
44-
SELECT create_hash_partitions('test_exprs.hash_rel','value * value2))',4);
4577
SELECT create_hash_partitions('test_exprs.hash_rel','value * value3',4);
4678

4779
/* Check that 'pathman_hooks_enabled' is true (1 partition in plan)*/
@@ -75,13 +107,13 @@ INSERT INTO test_exprs.range_rel (dt, txt)
75107
SELECT g, md5(g::TEXT)FROM generate_series('2015-01-01','2020-04-30','1 month'::interval)as g;
76108

77109

110+
111+
\set VERBOSITY default
112+
78113
/* Try using constant expression*/
79114
SELECT create_range_partitions('test_exprs.range_rel','''16 years''::interval',
80115
'15 years'::INTERVAL,'1 year'::INTERVAL,10);
81116

82-
83-
\set VERBOSITY default
84-
85117
/* Try using mutable expression*/
86118
SELECT create_range_partitions('test_exprs.range_rel','RANDOM()',
87119
'15 years'::INTERVAL,'1 year'::INTERVAL,10);

‎src/hooks.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ pathman_join_pathlist_hook(PlannerInfo *root,
9191
set_join_pathlist_next(root,joinrel,outerrel,
9292
innerrel,jointype,extra);
9393

94-
/* Hooks can be disabled */
95-
if (!pathman_hooks_enabled)
96-
return;
97-
9894
/* Check that both pg_pathman & RuntimeAppend nodes are enabled */
9995
if (!IsPathmanReady()|| !pg_pathman_enable_runtimeappend)
10096
return;
@@ -268,10 +264,6 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
268264
if (set_rel_pathlist_hook_next!=NULL)
269265
set_rel_pathlist_hook_next(root,rel,rti,rte);
270266

271-
/* Hooks can be disabled */
272-
if (!pathman_hooks_enabled)
273-
return;
274-
275267
/* Make sure that pg_pathman is ready */
276268
if (!IsPathmanReady())
277269
return;
@@ -533,7 +525,7 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
533525
uint32query_id=parse->queryId;
534526

535527
/* Save the result in case it changes */
536-
boolpathman_ready=pathman_hooks_enabled&&IsPathmanReady();
528+
boolpathman_ready=IsPathmanReady();
537529

538530
PG_TRY();
539531
{

‎src/include/relation_info.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ Datum cook_partitioning_expression(const Oid relid,
292292
constchar*expr_cstr,
293293
Oid*expr_type);
294294

295+
char*canonicalize_partitioning_expression(constOidrelid,
296+
constchar*expr_cstr);
297+
295298
/* Global invalidation routines */
296299
voiddelay_pathman_shutdown(void);
297300
voiddelay_invalidation_parent_rel(Oidparent);

‎src/nodes_common.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,6 @@ canonicalize_custom_exprs_mutator(Node *node, void *cxt)
353353
/* Restore original 'varattno' */
354354
var->varattno=var->varoattno;
355355

356-
/* Forget 'location' */
357-
var->location=-1;
358-
359356
return (Node*)var;
360357
}
361358

‎src/partition_creation.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,12 +1250,12 @@ check_range_available(Oid parent_relid,
12501250
if (raise_error)
12511251
elog(ERROR,"specified range [%s, %s) overlaps "
12521252
"with existing partitions",
1253-
!IsInfinite(start) ?
1254-
datum_to_cstring(BoundGetValue(start),value_type) :
1255-
"NULL",
1256-
!IsInfinite(end) ?
1257-
datum_to_cstring(BoundGetValue(end),value_type) :
1258-
"NULL");
1253+
IsInfinite(start) ?
1254+
"NULL" :
1255+
datum_to_cstring(BoundGetValue(start),value_type),
1256+
IsInfinite(end) ?
1257+
"NULL" :
1258+
datum_to_cstring(BoundGetValue(end),value_type));
12591259

12601260
elsereturn false;
12611261
}

‎src/pl_funcs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include"nodes/nodeFuncs.h"
3535
#include"utils/builtins.h"
3636
#include"utils/inval.h"
37-
#include"utils/ruleutils.h"
3837
#include"utils/snapmgr.h"
3938
#include"utils/lsyscache.h"
4039
#include"utils/syscache.h"
@@ -833,9 +832,7 @@ add_to_pathman_config(PG_FUNCTION_ARGS)
833832
expr_datum=cook_partitioning_expression(relid,expression,&expr_type);
834833

835834
/* Canonicalize user's expression (trim whitespaces etc) */
836-
expression=deparse_expression(stringToNode(TextDatumGetCString(expr_datum)),
837-
deparse_context_for(get_rel_name(relid),relid),
838-
false, false);
835+
expression=canonicalize_partitioning_expression(relid,expression);
839836

840837
/* Check hash function for HASH partitioning */
841838
if (parttype==PT_HASH)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp