@@ -51,43 +51,10 @@ BEGIN
5151 INSERT INTO @extschema@.pathman_config (partrel, attname, parttype)
5252 VALUES (parent_relid, attribute, 1 );
5353
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);
9158
9259 /* Notify backend about changes */
9360 PERFORM @extschema@.on_create_partitions(parent_relid);
@@ -202,7 +169,7 @@ BEGIN
202169 old_fields, att_fmt, new_fields, child_relname_format,
203170 @extschema@.get_type_hash_func(atttype)::TEXT );
204171
205- /* Create trigger on every partition */
172+ /* Create trigger on each partition */
206173 FOR num IN 0 ..partitions_count- 1
207174 LOOP
208175 EXECUTE format(trigger,
@@ -215,6 +182,16 @@ BEGIN
215182END
216183$$ LANGUAGE plpgsql;
217184
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+
218195/*
219196 * Returns hash function OID for specified type
220197 */
0 commit comments