31
31
* partrel - regclass (relation type, stored as Oid)
32
32
* enable_parent - add parent table to plan
33
33
* auto - enable automatic partition creation
34
+ * init_callback - cb to be executed on partition creation
34
35
*/
35
36
CREATE TABLE IF NOT EXISTS @
[email protected] _config_params (
36
37
partrel REGCLASS NOT NULL PRIMARY KEY ,
37
38
enable_parent BOOLEAN NOT NULL DEFAULT TRUE,
38
- auto BOOLEAN NOT NULL DEFAULT TRUE
39
+ auto BOOLEAN NOT NULL DEFAULT TRUE,
40
+ init_callback REGPROCEDURE NOT NULL DEFAULT 0
39
41
);
40
42
CREATE UNIQUE INDEX i_pathman_config_params
41
43
ON @
[email protected] _config_params(partrel);
@@ -85,15 +87,15 @@ BEGIN
85
87
RETURN count (* ) FROM pg_inherits WHERE inhparent = relation;
86
88
END
87
89
$$
88
- LANGUAGE plpgsql;
90
+ LANGUAGE plpgsql STRICT ;
89
91
90
92
/*
91
93
* Add a row describing the optional parameter to pathman_config_params.
92
94
*/
93
95
CREATE
OR REPLACE FUNCTION @
[email protected] _set_param(
94
96
relation REGCLASS,
95
97
param TEXT ,
96
- value BOOLEAN )
98
+ value ANYELEMENT )
97
99
RETURNS VOID AS
98
100
$$
99
101
BEGIN
106
108
LANGUAGE plpgsql;
107
109
108
110
/*
109
- * Include parent relation into query plan's for specified relation.
110
- */
111
- CREATE
OR REPLACE FUNCTION @
[email protected] _parent(relation REGCLASS)
112
- RETURNS VOID AS
113
- $$
114
- BEGIN
115
- PERFORM @
[email protected] _set_param(relation,
' enable_parent' , True);
116
- END
117
- $$
118
- LANGUAGE plpgsql;
119
-
120
- /*
121
- * Do not include parent relation into query plan's for specified relation.
111
+ * Include\exclude parent relation in query plan.
122
112
*/
123
- CREATE
OR REPLACE FUNCTION @
[email protected] _parent(relation REGCLASS)
113
+ CREATE
OR REPLACE FUNCTION @
[email protected] _enable_parent(
114
+ relation REGCLASS,
115
+ value BOOLEAN )
124
116
RETURNS VOID AS
125
117
$$
126
118
BEGIN
127
- PERFORM @
[email protected] _set_param(relation,
' enable_parent' ,
False );
119
+ PERFORM @
[email protected] _set_param(relation,
' enable_parent' ,
value );
128
120
END
129
121
$$
130
- LANGUAGE plpgsql;
122
+ LANGUAGE plpgsql STRICT ;
131
123
132
124
/*
133
- * Enable automatic partition creation.
125
+ * Enable\disable automatic partition creation.
134
126
*/
135
- CREATE
OR REPLACE FUNCTION @
[email protected] _auto(relation REGCLASS)
127
+ CREATE
OR REPLACE FUNCTION @
[email protected] _auto(
128
+ relation REGCLASS,
129
+ value BOOLEAN )
136
130
RETURNS VOID AS
137
131
$$
138
132
BEGIN
139
- PERFORM @
[email protected] _set_param(relation,
' auto' ,
True );
133
+ PERFORM @
[email protected] _set_param(relation,
' auto' ,
value );
140
134
END
141
135
$$
142
- LANGUAGE plpgsql;
136
+ LANGUAGE plpgsql STRICT ;
143
137
144
138
/*
145
- * Disable automatic partition creation.
139
+ * Set partition creation callback
146
140
*/
147
- CREATE
OR REPLACE FUNCTION @
[email protected] _auto(relation REGCLASS)
141
+ CREATE
OR REPLACE FUNCTION @
[email protected] _part_init_callback(
142
+ relation REGCLASS,
143
+ callback REGPROC)
148
144
RETURNS VOID AS
149
145
$$
150
146
BEGIN
151
- PERFORM @
[email protected] _set_param(relation,
' auto' , False);
147
+ PERFORM @
[email protected] _on_partition_created_callback(callback);
148
+ PERFORM @
[email protected] _set_param(relation,
' init_callback' , callback);
152
149
END
153
150
$$
154
151
LANGUAGE plpgsql;
@@ -201,6 +198,7 @@ DECLARE
201
198
v_limit_clause TEXT := ' ' ;
202
199
v_where_clause TEXT := ' ' ;
203
200
ctids TID[];
201
+
204
202
BEGIN
205
203
SELECT attname INTO v_attr
206
204
FROM @
[email protected] _config
WHERE partrel
= p_relation;
@@ -276,7 +274,7 @@ BEGIN
276
274
RETURN;
277
275
END
278
276
$$
279
- LANGUAGE plpgsql
277
+ LANGUAGE plpgsql STRICT
280
278
SET pg_pathman .enable_partitionfilter = on ; /* ensures that PartitionFilter is ON */
281
279
282
280
/*
@@ -296,7 +294,7 @@ BEGIN
296
294
PERFORM @
[email protected] _remove_partitions(parent_relid);
297
295
END
298
296
$$
299
- LANGUAGE plpgsql;
297
+ LANGUAGE plpgsql STRICT ;
300
298
301
299
/*
302
300
* Aggregates several common relation checks before partitioning.
@@ -365,7 +363,7 @@ BEGIN
365
363
INTO schema, relname;
366
364
END
367
365
$$
368
- LANGUAGE plpgsql;
366
+ LANGUAGE plpgsql STRICT ;
369
367
370
368
/*
371
369
* Returns schema-qualified name for table
@@ -384,7 +382,7 @@ BEGIN
384
382
WHERE oid = cls::oid );
385
383
END
386
384
$$
387
- LANGUAGE plpgsql;
385
+ LANGUAGE plpgsql STRICT ;
388
386
389
387
/*
390
388
* Validates relation name. It must be schema qualified
@@ -484,7 +482,7 @@ BEGIN
484
482
EXECUTE format(' DROP FUNCTION IF EXISTS %s() CASCADE' ,
485
483
@
[email protected] _update_trigger_func_name(parent_relid));
486
484
END
487
- $$ LANGUAGE plpgsql;
485
+ $$ LANGUAGE plpgsql STRICT ;
488
486
489
487
/*
490
488
* Drop partitions
@@ -569,7 +567,7 @@ BEGIN
569
567
pg_get_constraintdef(rec .conid ));
570
568
END LOOP;
571
569
END
572
- $$ LANGUAGE plpgsql;
570
+ $$ LANGUAGE plpgsql STRICT ;
573
571
574
572
575
573
/*
@@ -703,3 +701,41 @@ LANGUAGE C STRICT;
703
701
CREATE
OR REPLACE FUNCTION @
[email protected] _capture()
704
702
RETURNS VOID AS ' pg_pathman' , ' debug_capture'
705
703
LANGUAGE C STRICT;
704
+
705
+ /*
706
+ * Return tablespace name for specified relation.
707
+ */
708
+ CREATE
OR REPLACE FUNCTION @
[email protected] _rel_tablespace_name(relation REGCLASS)
709
+ RETURNS TEXT AS ' pg_pathman' , ' get_rel_tablespace_name'
710
+ LANGUAGE C STRICT;
711
+
712
+ /*
713
+ * Checks that callback function meets specific requirements. Particularly it
714
+ * must have the only JSONB argument and VOID return type.
715
+ */
716
+ CREATE
OR REPLACE FUNCTION @
[email protected] _on_partition_created_callback(callback REGPROC)
717
+ RETURNS VOID AS ' pg_pathman' , ' validate_on_part_init_callback_pl'
718
+ LANGUAGE C STRICT;
719
+
720
+
721
+ /*
722
+ * Invoke init_callback on RANGE partition.
723
+ */
724
+ CREATE
OR REPLACE FUNCTION @
[email protected] _on_partition_created_callback(
725
+ parent_relid REGCLASS,
726
+ partition REGCLASS,
727
+ init_callback REGPROCEDURE,
728
+ start_value ANYELEMENT,
729
+ end_value ANYELEMENT)
730
+ RETURNS VOID AS ' pg_pathman' , ' invoke_on_partition_created_callback'
731
+ LANGUAGE C;
732
+
733
+ /*
734
+ * Invoke init_callback on HASH partition.
735
+ */
736
+ CREATE
OR REPLACE FUNCTION @
[email protected] _on_partition_created_callback(
737
+ parent_relid REGCLASS,
738
+ partition REGCLASS,
739
+ init_callback REGPROCEDURE)
740
+ RETURNS VOID AS ' pg_pathman' , ' invoke_on_partition_created_callback'
741
+ LANGUAGE C;
0 commit comments