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

Commitc3e8ed8

Browse files
committed
reimplement HASH partition creation machinery in C language
1 parent7d81364 commitc3e8ed8

File tree

9 files changed

+404
-109
lines changed

9 files changed

+404
-109
lines changed

‎expected/pathman_calamity.out

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ SHOW pg_pathman.enable;
293293
on
294294
(1 row)
295295

296+
/* check function create_hash_partitions_internal() (called for the 2nd time) */
297+
CREATE TABLE calamity.hash_two_times(val serial);
298+
SELECT create_hash_partitions('calamity.hash_two_times', 'val', 2);
299+
create_hash_partitions
300+
------------------------
301+
2
302+
(1 row)
303+
304+
SELECT create_hash_partitions_internal('calamity.hash_two_times', 'val', 2);
305+
ERROR: cannot add new HASH partitions
296306
DROP SCHEMA calamity CASCADE;
297-
NOTICE: drop cascades to8 other objects
307+
NOTICE: drop cascades to11 other objects
298308
DROP EXTENSION pg_pathman;

‎hash.sql

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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 partnumIN0..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_paramsAS params
84-
ONparams.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 onevery partition*/
172+
/* Create trigger oneach partition*/
206173
FOR numIN0..partitions_count-1
207174
LOOP
208175
EXECUTE format(trigger,
@@ -215,6 +182,16 @@ BEGIN
215182
END
216183
$$ LANGUAGE plpgsql;
217184

185+
/*
186+
* Just create HASH partitions, called by create_hash_partitions().
187+
*/
188+
CREATEOR REPLACE FUNCTION @extschema@.create_hash_partitions_internal(
189+
parent_relidREGCLASS,
190+
attributeTEXT,
191+
partitions_countINTEGER)
192+
RETURNS VOIDAS'pg_pathman','create_hash_partitions_internal'
193+
LANGUAGE C STRICT;
194+
218195
/*
219196
* Returns hash function OID for specified type
220197
*/

‎sql/pathman_calamity.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ ALTER TABLE calamity.wrong_partition DROP CONSTRAINT pathman_wrong_partition_1_c
109109
/* check GUC variable*/
110110
SHOWpg_pathman.enable;
111111

112+
/* check function create_hash_partitions_internal() (called for the 2nd time)*/
113+
CREATETABLEcalamity.hash_two_times(valserial);
114+
SELECT create_hash_partitions('calamity.hash_two_times','val',2);
115+
SELECT create_hash_partitions_internal('calamity.hash_two_times','val',2);
116+
112117

113118
DROPSCHEMA calamity CASCADE;
114119
DROP EXTENSION pg_pathman;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp