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

Commitd1556b4

Browse files
committed
refactoring, add column 'spawn_using_bgw' to PATHMAN_CONFIG_PARAMS
1 parent2a31969 commitd1556b4

17 files changed

+201
-131
lines changed

‎expected/pathman_callbacks.out

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,66 @@ SELECT set_init_callback('callbacks.abc',
2626
(1 row)
2727

2828
INSERT INTO callbacks.abc VALUES (123, 1);
29-
INSERT INTO callbacks.abc VALUES (223, 1);
29+
INSERT INTO callbacks.abc VALUES (223, 1); /* show warning */
30+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_3", "range_max": "301", "range_min": "201"}
31+
SELECT set_spawn_using_bgw('callbacks.abc', true);
32+
set_spawn_using_bgw
33+
---------------------
34+
35+
(1 row)
36+
37+
SELECT get_number_of_partitions('callbacks.abc');
38+
get_number_of_partitions
39+
--------------------------
40+
3
41+
(1 row)
42+
43+
INSERT INTO callbacks.abc VALUES (323, 1);
44+
SELECT get_number_of_partitions('callbacks.abc'); /* +1 partition (created by BGW) */
45+
get_number_of_partitions
46+
--------------------------
47+
4
48+
(1 row)
49+
50+
SELECT set_spawn_using_bgw('callbacks.abc', false);
51+
set_spawn_using_bgw
52+
---------------------
53+
54+
(1 row)
55+
3056
SELECT append_range_partition('callbacks.abc');
31-
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_4", "range_max": "401", "range_min": "301"}
57+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_5", "range_max": "501", "range_min": "401"}
3258
append_range_partition
3359
------------------------
34-
callbacks.abc_4
60+
callbacks.abc_5
3561
(1 row)
3662

3763
SELECT prepend_range_partition('callbacks.abc');
38-
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_5", "range_max": "1", "range_min": "-99"}
64+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_6", "range_max": "1", "range_min": "-99"}
3965
prepend_range_partition
4066
-------------------------
41-
callbacks.abc_5
67+
callbacks.abc_6
4268
(1 row)
4369

44-
SELECT add_range_partition('callbacks.abc',401, 502);
45-
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_6", "range_max": "502", "range_min": "401"}
70+
SELECT add_range_partition('callbacks.abc',501, 602);
71+
WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_7", "range_max": "602", "range_min": "501"}
4672
add_range_partition
4773
---------------------
48-
callbacks.abc_6
74+
callbacks.abc_7
4975
(1 row)
5076

5177
SELECT drop_partitions('callbacks.abc');
5278
NOTICE: function callbacks.abc_upd_trig_func() does not exist, skipping
5379
NOTICE: 0 rows copied from callbacks.abc_1
5480
NOTICE: 1 rows copied from callbacks.abc_2
5581
NOTICE: 1 rows copied from callbacks.abc_3
56-
NOTICE:0 rows copied from callbacks.abc_4
82+
NOTICE:1 rows copied from callbacks.abc_4
5783
NOTICE: 0 rows copied from callbacks.abc_5
5884
NOTICE: 0 rows copied from callbacks.abc_6
85+
NOTICE: 0 rows copied from callbacks.abc_7
5986
drop_partitions
6087
-----------------
61-
6
88+
7
6289
(1 row)
6390

6491
/* set callback to be called on HASH partitions */

‎expected/pathman_permissions.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ SELECT * FROM pathman_config;
3939
(1 row)
4040

4141
SELECT * FROM pathman_config_params;
42-
partrel | enable_parent | auto | init_callback
43-
-------------------------+---------------+------+---------------
44-
permissions.user1_table | f | t | -
42+
partrel | enable_parent | auto | init_callback| spawn_using_bgw
43+
-------------------------+---------------+------+---------------+-----------------
44+
permissions.user1_table | f | t | - | f
4545
(1 row)
4646

4747
/* Should fail */

‎init.sql

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
2626
CHECK (parttypeIN (1,2))/* check for allowed part types*/
2727
);
2828

29+
30+
/*
31+
* Checks that callback function meets specific requirements.
32+
* Particularly it must have the only JSONB argument and VOID return type.
33+
*
34+
* NOTE: this function is used in CHECK CONSTRAINT.
35+
*/
36+
CREATEOR REPLACE FUNCTION @extschema@.validate_part_callback(
37+
callbackREGPROC,
38+
raise_errorBOOL DEFAULT FALSE)
39+
RETURNS BOOLAS'pg_pathman','validate_part_callback_pl'
40+
LANGUAGE C STRICT;
41+
42+
2943
/*
3044
* Optional parameters for partitioned tables.
3145
*partrel - regclass (relation type, stored as Oid)
@@ -37,10 +51,11 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config_params (
3751
partrelREGCLASSNOT NULLPRIMARY KEY,
3852
enable_parentBOOLEANNOT NULL DEFAULT FALSE,
3953
autoBOOLEANNOT NULL DEFAULT TRUE,
40-
init_callbackREGPROCEDURENOT NULL DEFAULT0
54+
init_callbackREGPROCEDURENOT NULL DEFAULT0,
55+
spawn_using_bgwBOOLEANNOT NULL DEFAULT FALSE
56+
57+
CHECK (@extschema@.validate_part_callback(init_callback))/* check signature*/
4158
);
42-
CREATEUNIQUE INDEXi_pathman_config_params
43-
ON @extschema@.pathman_config_params(partrel);
4459

4560
GRANTSELECT, INSERT,UPDATE,DELETE
4661
ON @extschema@.pathman_config, @extschema@.pathman_config_params
@@ -120,7 +135,7 @@ BEGIN
120135
USING relation, value;
121136
END
122137
$$
123-
LANGUAGE plpgsql;
138+
LANGUAGE plpgsql STRICT;
124139

125140
/*
126141
* Include\exclude parent relation in query plan.
@@ -159,11 +174,25 @@ CREATE OR REPLACE FUNCTION @extschema@.set_init_callback(
159174
RETURNS VOIDAS
160175
$$
161176
BEGIN
162-
PERFORM @extschema@.validate_on_partition_created_callback(callback);
163177
PERFORM @extschema@.pathman_set_param(relation,'init_callback', callback);
164178
END
165179
$$
166-
LANGUAGE plpgsql;
180+
LANGUAGE plpgsql STRICT;
181+
182+
/*
183+
* Set 'spawn using BGW' option
184+
*/
185+
CREATEOR REPLACE FUNCTION @extschema@.set_spawn_using_bgw(
186+
relationREGCLASS,
187+
valueBOOLEAN)
188+
RETURNS VOIDAS
189+
$$
190+
BEGIN
191+
PERFORM @extschema@.pathman_set_param(relation,'spawn_using_bgw', value);
192+
END
193+
$$
194+
LANGUAGE plpgsql STRICT;
195+
167196

168197
/*
169198
* Show all existing parents and partitions.
@@ -752,15 +781,6 @@ CREATE OR REPLACE FUNCTION @extschema@.debug_capture()
752781
RETURNS VOIDAS'pg_pathman','debug_capture'
753782
LANGUAGE C STRICT;
754783

755-
/*
756-
* Checks that callback function meets specific requirements. Particularly it
757-
* must have the only JSONB argument and VOID return type.
758-
*/
759-
CREATEOR REPLACE FUNCTION @extschema@.validate_on_partition_created_callback(
760-
callbackREGPROC)
761-
RETURNS VOIDAS'pg_pathman','validate_on_part_init_callback_pl'
762-
LANGUAGE C STRICT;
763-
764784

765785
/*
766786
* Invoke init_callback on RANGE partition.

‎sql/pathman_callbacks.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,18 @@ SELECT set_init_callback('callbacks.abc',
2222
'callbacks.abc_on_part_created_callback');
2323

2424
INSERT INTOcallbacks.abcVALUES (123,1);
25-
INSERT INTOcallbacks.abcVALUES (223,1);
25+
INSERT INTOcallbacks.abcVALUES (223,1);/* show warning*/
26+
27+
SELECT set_spawn_using_bgw('callbacks.abc', true);
28+
SELECT get_number_of_partitions('callbacks.abc');
29+
INSERT INTOcallbacks.abcVALUES (323,1);
30+
SELECT get_number_of_partitions('callbacks.abc');/* +1 partition (created by BGW)*/
31+
SELECT set_spawn_using_bgw('callbacks.abc', false);
32+
2633

2734
SELECT append_range_partition('callbacks.abc');
2835
SELECT prepend_range_partition('callbacks.abc');
29-
SELECT add_range_partition('callbacks.abc',401,502);
36+
SELECT add_range_partition('callbacks.abc',501,602);
3037

3138
SELECT drop_partitions('callbacks.abc');
3239

‎src/init.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ init_main_pathman_toggles(void)
128128
"Enables automatic partition creation",
129129
NULL,
130130
&pg_pathman_init_state.auto_partition,
131-
true,
131+
DEFAULT_AUTO,
132132
PGC_SUSET,
133133
0,
134134
NULL,
@@ -730,6 +730,7 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
730730
Assert(!isnull[Anum_pathman_config_params_enable_parent-1]);
731731
Assert(!isnull[Anum_pathman_config_params_auto-1]);
732732
Assert(!isnull[Anum_pathman_config_params_init_callback-1]);
733+
Assert(!isnull[Anum_pathman_config_params_spawn_using_bgw-1]);
733734
}
734735

735736
/* Clean resources */

‎src/init.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ extern PathmanInitState pg_pathman_init_state;
8787
} while (0)
8888

8989

90+
/* Default column values for PATHMAN_CONFIG_PARAMS */
91+
#defineDEFAULT_ENABLE_PARENTfalse
92+
#defineDEFAULT_AUTOtrue
93+
#defineDEFAULT_INIT_CALLBACKInvalidOid
94+
#defineDEFAULT_SPAWN_USING_BGWfalse
95+
96+
9097
/*
9198
* Save and restore PathmanInitState.
9299
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp