Skip to content

Commit 2ca82a8

Browse files
committed
pathman: pl functions fixes
1 parent 7915152 commit 2ca82a8

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

contrib/pathman/init.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ create_part_relations_hashtable()
9797
hash_destroy(relations);
9898

9999
relations = ShmemInitHash("Partitioning relation info",
100-
128, 128,
100+
16, 16,
101101
&ctl, HASH_ELEM | HASH_BLOBS);
102102
}
103103

@@ -175,7 +175,7 @@ create_hash_restrictions_hashtable()
175175
hash_destroy(hash_restrictions);
176176

177177
hash_restrictions = ShmemInitHash("pg_pathman hash restrictions",
178-
1024, 1024,
178+
128, 128,
179179
&ctl, HASH_ELEM | HASH_BLOBS);
180180
}
181181

@@ -312,8 +312,7 @@ create_range_restrictions_hashtable()
312312
memset(&ctl, 0, sizeof(ctl));
313313
ctl.keysize = sizeof(int);
314314
ctl.entrysize = sizeof(RangeRelation);
315-
316315
range_restrictions = ShmemInitHash("pg_pathman range restrictions",
317-
16, 16,
316+
512, 512,
318317
&ctl, HASH_ELEM | HASH_BLOBS);
319318
}

contrib/pathman/pathman.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,9 @@ on_partitions_removed(PG_FUNCTION_ARGS) {
827827
prel = (PartRelationInfo *)
828828
hash_search(relations, (const void *) &relid, HASH_FIND, 0);
829829

830+
if (!prel)
831+
PG_RETURN_NULL();
832+
830833
/* remove children relations */
831834
switch (prel->parttype)
832835
{

contrib/pathman/sql/range.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,14 @@ RETURNS VOID AS
159159
$$
160160
DECLARE
161161
v_child_relname TEXT;
162+
v_check TEXT;
163+
v_min_value TEXT;
164+
v_max_value TEXT;
165+
v_attname TEXT;
162166
BEGIN
167+
v_attname := attname FROM pg_pathman_rels
168+
WHERE relname = v_parent_relname;
169+
163170
IF v_type = 'time' THEN
164171
v_child_relname := format('%s_%s'
165172
, v_parent_relname
@@ -190,13 +197,24 @@ BEGIN
190197
, v_start_value::TIMESTAMP
191198
, v_start_value::TIMESTAMP + v_interval::INTERVAL
192199
, v_child_relname);
200+
v_min_value := to_char(v_start_value::TIMESTAMP, 'YYYY-MM-DD HH:MI:SS');
201+
v_max_value := to_char(v_start_value::TIMESTAMP + v_interval::INTERVAL, 'YYYY-MM-DD HH:MI:SS');
193202
ELSIF v_type = 'num' THEN
194203
INSERT INTO pg_pathman_range_rels (parent, min_num, max_num, child)
195204
VALUES (v_parent_relname
196205
, v_start_value::DOUBLE PRECISION
197206
, v_start_value::DOUBLE PRECISION + v_interval::DOUBLE PRECISION
198207
, v_child_relname);
208+
v_min_value := v_start_value::DOUBLE PRECISION;
209+
v_max_value := v_start_value::DOUBLE PRECISION + v_interval::DOUBLE PRECISION;
199210
END IF;
211+
212+
EXECUTE format('ALTER TABLE %s ADD CHECK (%s >= ''%s'' AND %s < ''%s'')'
213+
, v_child_relname
214+
, v_attname
215+
, v_min_value
216+
, v_attname
217+
, v_max_value);
200218
END
201219
$$ LANGUAGE plpgsql;
202220

@@ -298,6 +316,24 @@ BEGIN
298316
END
299317
$$ LANGUAGE plpgsql;
300318

319+
/*
320+
*
321+
*/
322+
CREATE OR REPLACE FUNCTION disable_range_partitions(IN relation TEXT)
323+
RETURNS VOID AS
324+
$$
325+
DECLARE
326+
v_relid INTEGER;
327+
v_rec RECORD;
328+
BEGIN
329+
DELETE FROM pg_pathman_rels WHERE relname = relation;
330+
DELETE FROM pg_pathman_range_rels WHERE parent = relation;
331+
332+
/* Notify backend about changes */
333+
PERFORM pg_pathman_on_remove_partitions(v_relid);
334+
END
335+
$$ LANGUAGE plpgsql;
336+
301337
/*
302338
* Drop trigger
303339
*/

0 commit comments

Comments
 (0)