@@ -51,43 +51,10 @@ BEGIN
51
51
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype)
52
52
VALUES (parent_relid, attribute, 1 );
53
53
54
- /* Create partitions and update pg_pathman configuration */
55
- FOR partnum IN 0 ..partitions_count- 1
56
- LOOP
57
- v_child_relname := format(' %s.%s' ,
58
- quote_ident(v_plain_schema),
59
- quote_ident(v_plain_relname || ' _' || partnum));
60
-
61
- EXECUTE format(
62
- ' CREATE TABLE %1$s (LIKE %2$s INCLUDING ALL) INHERITS (%2$s) TABLESPACE %s' ,
63
- v_child_relname,
64
- parent_relid::TEXT ,
65
- @extschema@.get_rel_tablespace_name(parent_relid));
66
-
67
- EXECUTE format(' ALTER TABLE %s ADD CONSTRAINT %s
68
- CHECK (@extschema@.get_hash_part_idx(%s(%s), %s) = %s)' ,
69
- v_child_relname,
70
- @extschema@.build_check_constraint_name(v_child_relname::REGCLASS,
71
- attribute),
72
- v_hashfunc::TEXT ,
73
- attribute,
74
- partitions_count,
75
- partnum);
76
-
77
- PERFORM @extschema@.copy_foreign_keys(parent_relid, v_child_relname::REGCLASS);
78
-
79
- /* Fetch init_callback from 'params' table */
80
- WITH stub_callback(stub) as (values (0 ))
81
- SELECT coalesce(init_callback, 0 ::REGPROCEDURE)
82
- FROM stub_callback
83
- LEFT JOIN @extschema@.pathman_config_params AS params
84
- ON params .partrel = parent_relid
85
- INTO v_init_callback;
86
-
87
- PERFORM @extschema@.invoke_on_partition_created_callback(parent_relid,
88
- v_child_relname::REGCLASS,
89
- v_init_callback);
90
- END LOOP;
54
+ /* Create partitions */
55
+ PERFORM @extschema@.create_hash_partitions_internal(parent_relid,
56
+ attribute,
57
+ partitions_count);
91
58
92
59
/* Notify backend about changes */
93
60
PERFORM @extschema@.on_create_partitions(parent_relid);
@@ -202,7 +169,7 @@ BEGIN
202
169
old_fields, att_fmt, new_fields, child_relname_format,
203
170
@extschema@.get_type_hash_func(atttype)::TEXT );
204
171
205
- /* Create trigger on every partition */
172
+ /* Create trigger on each partition */
206
173
FOR num IN 0 ..partitions_count- 1
207
174
LOOP
208
175
EXECUTE format(trigger,
@@ -215,6 +182,16 @@ BEGIN
215
182
END
216
183
$$ LANGUAGE plpgsql;
217
184
185
+ /*
186
+ * Just create HASH partitions, called by create_hash_partitions().
187
+ */
188
+ CREATE OR REPLACE FUNCTION @extschema@.create_hash_partitions_internal(
189
+ parent_relid REGCLASS,
190
+ attribute TEXT ,
191
+ partitions_count INTEGER )
192
+ RETURNS VOID AS ' pg_pathman' , ' create_hash_partitions_internal'
193
+ LANGUAGE C STRICT;
194
+
218
195
/*
219
196
* Returns hash function OID for specified type
220
197
*/
0 commit comments