Skip to content

Commit 27fcbf6

Browse files
committed
update README.md (new features & corrections), minor improvements in pl/PgSQL API, rename function set_part_init_callback() -> set_init_callback()
1 parent f831fc2 commit 27fcbf6

File tree

7 files changed

+161
-82
lines changed

7 files changed

+161
-82
lines changed

README.md

Lines changed: 114 additions & 39 deletions
Large diffs are not rendered by default.

expected/pathman_basic.out

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -889,9 +889,9 @@ SELECT * FROM test.hash_rel WHERE id = 123;
889889
*/
890890
SELECT pathman.drop_partitions('test.hash_rel');
891891
NOTICE: drop cascades to 3 other objects
892-
NOTICE: 2 rows copied from test.hash_rel_2
893-
NOTICE: 3 rows copied from test.hash_rel_1
894892
NOTICE: 2 rows copied from test.hash_rel_0
893+
NOTICE: 3 rows copied from test.hash_rel_1
894+
NOTICE: 2 rows copied from test.hash_rel_2
895895
drop_partitions
896896
-----------------
897897
3
@@ -925,11 +925,11 @@ SELECT COUNT(*) FROM ONLY test.hash_rel;
925925
DROP TABLE test.hash_rel CASCADE;
926926
SELECT pathman.drop_partitions('test.num_range_rel');
927927
NOTICE: drop cascades to 4 other objects
928-
NOTICE: 0 rows copied from test.num_range_rel_6
929-
NOTICE: 2 rows copied from test.num_range_rel_4
930-
NOTICE: 1000 rows copied from test.num_range_rel_3
931-
NOTICE: 1000 rows copied from test.num_range_rel_2
932928
NOTICE: 998 rows copied from test.num_range_rel_1
929+
NOTICE: 1000 rows copied from test.num_range_rel_2
930+
NOTICE: 1000 rows copied from test.num_range_rel_3
931+
NOTICE: 2 rows copied from test.num_range_rel_4
932+
NOTICE: 0 rows copied from test.num_range_rel_6
933933
drop_partitions
934934
-----------------
935935
5
@@ -1108,9 +1108,9 @@ EXPLAIN (COSTS OFF) SELECT * FROM test."TeSt" WHERE a = 1;
11081108

11091109
SELECT pathman.drop_partitions('test."TeSt"');
11101110
NOTICE: drop cascades to 3 other objects
1111-
NOTICE: 3 rows copied from test."TeSt_2"
1112-
NOTICE: 0 rows copied from test."TeSt_1"
11131111
NOTICE: 0 rows copied from test."TeSt_0"
1112+
NOTICE: 0 rows copied from test."TeSt_1"
1113+
NOTICE: 3 rows copied from test."TeSt_2"
11141114
drop_partitions
11151115
-----------------
11161116
3
@@ -1163,11 +1163,11 @@ SELECT pathman.split_range_partition('test."RangeRel_1"', '2015-01-01'::DATE);
11631163

11641164
SELECT pathman.drop_partitions('test."RangeRel"');
11651165
NOTICE: function test.RangeRel_upd_trig_func() does not exist, skipping
1166-
NOTICE: 1 rows copied from test."RangeRel_6"
1167-
NOTICE: 0 rows copied from test."RangeRel_4"
1168-
NOTICE: 1 rows copied from test."RangeRel_3"
1169-
NOTICE: 1 rows copied from test."RangeRel_2"
11701166
NOTICE: 0 rows copied from test."RangeRel_1"
1167+
NOTICE: 1 rows copied from test."RangeRel_2"
1168+
NOTICE: 1 rows copied from test."RangeRel_3"
1169+
NOTICE: 0 rows copied from test."RangeRel_4"
1170+
NOTICE: 1 rows copied from test."RangeRel_6"
11711171
drop_partitions
11721172
-----------------
11731173
5
@@ -1199,9 +1199,9 @@ SELECT pathman.create_range_partitions('test."RangeRel"', 'id', 1, 100, 3);
11991199

12001200
SELECT pathman.drop_partitions('test."RangeRel"');
12011201
NOTICE: function test.RangeRel_upd_trig_func() does not exist, skipping
1202-
NOTICE: 0 rows copied from test."RangeRel_3"
1203-
NOTICE: 0 rows copied from test."RangeRel_2"
12041202
NOTICE: 0 rows copied from test."RangeRel_1"
1203+
NOTICE: 0 rows copied from test."RangeRel_2"
1204+
NOTICE: 0 rows copied from test."RangeRel_3"
12051205
drop_partitions
12061206
-----------------
12071207
3
@@ -1358,20 +1358,20 @@ DELETE FROM range_rel r USING tmp t WHERE r.dt = '2010-01-02' AND r.id = t.id;
13581358
/* Create range partitions from whole range */
13591359
SELECT drop_partitions('range_rel');
13601360
NOTICE: function public.range_rel_upd_trig_func() does not exist, skipping
1361-
NOTICE: 0 rows copied from range_rel_15
1362-
NOTICE: 0 rows copied from range_rel_14
1363-
NOTICE: 14 rows copied from range_rel_13
1364-
NOTICE: 31 rows copied from range_rel_12
1365-
NOTICE: 30 rows copied from range_rel_11
1366-
NOTICE: 31 rows copied from range_rel_10
1367-
NOTICE: 30 rows copied from range_rel_9
1368-
NOTICE: 31 rows copied from range_rel_8
1369-
NOTICE: 31 rows copied from range_rel_7
1370-
NOTICE: 29 rows copied from range_rel_6
1371-
NOTICE: 31 rows copied from range_rel_5
1372-
NOTICE: 30 rows copied from range_rel_4
1373-
NOTICE: 31 rows copied from range_rel_3
13741361
NOTICE: 44 rows copied from range_rel_1
1362+
NOTICE: 31 rows copied from range_rel_3
1363+
NOTICE: 30 rows copied from range_rel_4
1364+
NOTICE: 31 rows copied from range_rel_5
1365+
NOTICE: 29 rows copied from range_rel_6
1366+
NOTICE: 31 rows copied from range_rel_7
1367+
NOTICE: 31 rows copied from range_rel_8
1368+
NOTICE: 30 rows copied from range_rel_9
1369+
NOTICE: 31 rows copied from range_rel_10
1370+
NOTICE: 30 rows copied from range_rel_11
1371+
NOTICE: 31 rows copied from range_rel_12
1372+
NOTICE: 14 rows copied from range_rel_13
1373+
NOTICE: 0 rows copied from range_rel_14
1374+
NOTICE: 0 rows copied from range_rel_15
13751375
drop_partitions
13761376
-----------------
13771377
14

expected/pathman_callbacks.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ NOTICE: sequence "abc_seq" does not exist, skipping
1818
2
1919
(1 row)
2020

21-
SELECT set_part_init_callback('callbacks.abc',
22-
'callbacks.abc_on_part_created_callback');
23-
set_part_init_callback
24-
------------------------
21+
SELECT set_init_callback('callbacks.abc',
22+
'callbacks.abc_on_part_created_callback');
23+
set_init_callback
24+
-------------------
2525

2626
(1 row)
2727

@@ -62,10 +62,10 @@ NOTICE: 0 rows copied from callbacks.abc_6
6262
(1 row)
6363

6464
/* set callback to be called on HASH partitions */
65-
SELECT set_part_init_callback('callbacks.abc',
66-
'callbacks.abc_on_part_created_callback');
67-
set_part_init_callback
68-
------------------------
65+
SELECT set_init_callback('callbacks.abc',
66+
'callbacks.abc_on_part_created_callback');
67+
set_init_callback
68+
-------------------
6969

7070
(1 row)
7171

hash.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ CREATE OR REPLACE FUNCTION @extschema@.create_hash_partitions(
1515
parent_relid REGCLASS,
1616
attribute TEXT,
1717
partitions_count INTEGER,
18-
partition_data BOOLEAN DEFAULT true)
18+
partition_data BOOLEAN DEFAULT TRUE)
1919
RETURNS INTEGER AS
2020
$$
2121
DECLARE

init.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ LANGUAGE plpgsql STRICT;
135135
/*
136136
* Set partition creation callback
137137
*/
138-
CREATE OR REPLACE FUNCTION @extschema@.set_part_init_callback(
138+
CREATE OR REPLACE FUNCTION @extschema@.set_init_callback(
139139
relation REGCLASS,
140-
callback REGPROC)
140+
callback REGPROC DEFAULT 0)
141141
RETURNS VOID AS
142142
$$
143143
BEGIN
@@ -535,7 +535,8 @@ BEGIN
535535

536536
FOR v_rec IN (SELECT inhrelid::REGCLASS AS tbl
537537
FROM pg_catalog.pg_inherits
538-
WHERE inhparent::regclass = parent_relid)
538+
WHERE inhparent::regclass = parent_relid
539+
ORDER BY inhrelid ASC)
539540
LOOP
540541
IF NOT delete_data THEN
541542
EXECUTE format('WITH part_data AS (DELETE FROM %s RETURNING *)

sql/pathman_callbacks.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ $$ language plpgsql;
1818
CREATE TABLE callbacks.abc(a serial, b int);
1919
SELECT create_range_partitions('callbacks.abc', 'a', 1, 100, 2);
2020

21-
SELECT set_part_init_callback('callbacks.abc',
22-
'callbacks.abc_on_part_created_callback');
21+
SELECT set_init_callback('callbacks.abc',
22+
'callbacks.abc_on_part_created_callback');
2323

2424
INSERT INTO callbacks.abc VALUES (123, 1);
2525
INSERT INTO callbacks.abc VALUES (223, 1);
@@ -32,8 +32,8 @@ SELECT drop_partitions('callbacks.abc');
3232

3333

3434
/* set callback to be called on HASH partitions */
35-
SELECT set_part_init_callback('callbacks.abc',
36-
'callbacks.abc_on_part_created_callback');
35+
SELECT set_init_callback('callbacks.abc',
36+
'callbacks.abc_on_part_created_callback');
3737
SELECT create_hash_partitions('callbacks.abc', 'a', 5);
3838

3939

src/utils.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ validate_on_part_init_cb(Oid procid, bool emit_error)
700700
Form_pg_proc functup;
701701
bool is_ok = true;
702702

703+
if (procid == InvalidOid)
704+
return true;
705+
703706
tp = SearchSysCache1(PROCOID, ObjectIdGetDatum(procid));
704707
if (!HeapTupleIsValid(tp))
705708
elog(ERROR, "cache lookup failed for function %u", procid);

0 commit comments

Comments
 (0)