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

Commite8a47aa

Browse files
committed
resolve conflicts caused by a merge of 'callbacks'
2 parents68bac64 +b84a0a5 commite8a47aa

File tree

13 files changed

+837
-334
lines changed

13 files changed

+837
-334
lines changed

‎expected/pg_pathman.out

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ SELECT * FROM test.hash_rel;
3535
3 | 3
3636
(3 rows)
3737

38-
SELECT pathman.disable_parent('test.hash_rel');
39-
disable_parent
40-
----------------
38+
SELECT pathman.set_enable_parent('test.hash_rel', false);
39+
set_enable_parent
40+
-------------------
4141

4242
(1 row)
4343

@@ -55,9 +55,9 @@ SELECT * FROM test.hash_rel;
5555
----+-------
5656
(0 rows)
5757

58-
SELECT pathman.enable_parent('test.hash_rel');
59-
enable_parent
60-
---------------
58+
SELECT pathman.set_enable_parent('test.hash_rel', true);
59+
set_enable_parent
60+
-------------------
6161

6262
(1 row)
6363

@@ -1260,17 +1260,17 @@ SELECT * FROM test.range_rel WHERE dt = '2015-03-15';
12601260
74 | Sun Mar 15 00:00:00 2015
12611261
(1 row)
12621262

1263-
SELECT pathman.disable_auto('test.range_rel');
1264-
disable_auto
1265-
--------------
1263+
SELECT pathman.set_auto('test.range_rel', false);
1264+
set_auto
1265+
----------
12661266

12671267
(1 row)
12681268

12691269
INSERT INTO test.range_rel (dt) VALUES ('2015-06-01');
12701270
ERROR: no suitable partition for key 'Mon Jun 01 00:00:00 2015'
1271-
SELECT pathman.enable_auto('test.range_rel');
1272-
enable_auto
1273-
-------------
1271+
SELECT pathman.set_auto('test.range_rel', true);
1272+
set_auto
1273+
----------
12741274

12751275
(1 row)
12761276

@@ -1768,3 +1768,58 @@ NOTICE: 100 rows copied from test_fkey_0
17681768
10
17691769
(1 row)
17701770

1771+
/* Check callbacks */
1772+
CREATE TABLE log(id serial, message text);
1773+
CREATE OR REPLACE FUNCTION abc_on_partition_created_callback(args JSONB)
1774+
RETURNS VOID AS $$
1775+
DECLARE
1776+
start_valueTEXT := args->>'start';
1777+
end_valueTEXT := args->'end';
1778+
BEGIN
1779+
INSERT INTO log(message)
1780+
VALUES (start_value || '-' || end_value);
1781+
END
1782+
$$ language plpgsql;
1783+
CREATE TABLE abc(a serial, b int);
1784+
SELECT create_range_partitions('abc', 'a', 1, 100, 2);
1785+
NOTICE: sequence "abc_seq" does not exist, skipping
1786+
create_range_partitions
1787+
-------------------------
1788+
2
1789+
(1 row)
1790+
1791+
SELECT set_part_init_callback('abc', 'abc_on_partition_created_callback');
1792+
set_part_init_callback
1793+
------------------------
1794+
1795+
(1 row)
1796+
1797+
INSERT INTO abc VALUES (123, 1);
1798+
INSERT INTO abc VALUES (223, 1);
1799+
SELECT append_range_partition('abc');
1800+
append_range_partition
1801+
------------------------
1802+
public.abc_4
1803+
(1 row)
1804+
1805+
SELECT prepend_range_partition('abc');
1806+
prepend_range_partition
1807+
-------------------------
1808+
public.abc_5
1809+
(1 row)
1810+
1811+
SELECT add_range_partition('abc', 401, 501);
1812+
add_range_partition
1813+
---------------------
1814+
public.abc_6
1815+
(1 row)
1816+
1817+
SELECT message FROM log ORDER BY id;
1818+
message
1819+
-----------
1820+
201-"301"
1821+
301-"401"
1822+
-99-"1"
1823+
401-"501"
1824+
(4 rows)
1825+

‎hash.sql

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ DECLARE
2424
v_plain_relnameTEXT;
2525
v_atttypeREGTYPE;
2626
v_hashfuncREGPROC;
27+
v_init_callbackREGPROCEDURE;
2728

2829
BEGIN
2930
IF partition_data= true THEN
@@ -56,9 +57,11 @@ BEGIN
5657
quote_ident(v_plain_schema),
5758
quote_ident(v_plain_relname||'_'|| partnum));
5859

59-
EXECUTE format('CREATE TABLE %1$s (LIKE %2$s INCLUDING ALL) INHERITS (%2$s)',
60-
v_child_relname,
61-
parent_relid::TEXT);
60+
EXECUTE format(
61+
'CREATE TABLE %1$s (LIKE %2$s INCLUDING ALL) INHERITS (%2$s) TABLESPACE %s',
62+
v_child_relname,
63+
parent_relid::TEXT,
64+
@extschema@.get_rel_tablespace_name(parent_relid));
6265

6366
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s
6467
CHECK (@extschema@.get_hash_part_idx(%s(%s), %s) = %s)',
@@ -71,17 +74,29 @@ BEGIN
7174
partnum);
7275

7376
PERFORM @extschema@.copy_foreign_keys(parent_relid, v_child_relname::REGCLASS);
77+
78+
/* Fetch init_callback from 'params' table*/
79+
WITH stub_callback(stub)as (values (0))
80+
SELECT coalesce(init_callback,0::REGPROCEDURE)
81+
FROM stub_callback
82+
LEFT JOIN @extschema@.pathman_config_paramsAS params
83+
ONparams.partrel= parent_relid
84+
INTO v_init_callback;
85+
86+
PERFORM @extschema@.invoke_on_partition_created_callback(parent_relid,
87+
v_child_relname::REGCLASS,
88+
v_init_callback);
7489
END LOOP;
7590

7691
/* Notify backend about changes*/
7792
PERFORM @extschema@.on_create_partitions(parent_relid);
7893

7994
/* Copy data*/
8095
IF partition_data= true THEN
81-
PERFORM @extschema@.disable_parent(parent_relid);
96+
PERFORM @extschema@.set_enable_parent(parent_relid, false);
8297
PERFORM @extschema@.partition_data(parent_relid);
8398
ELSE
84-
PERFORM @extschema@.enable_parent(parent_relid);
99+
PERFORM @extschema@.set_enable_parent(parent_relid, true);
85100
END IF;
86101

87102
RETURN partitions_count;
@@ -138,7 +153,6 @@ DECLARE
138153
funcnameTEXT;
139154
triggernameTEXT;
140155
atttypeREGTYPE;
141-
hashfuncTEXT;
142156
partitions_countINTEGER;
143157

144158
BEGIN

‎init.sql

Lines changed: 68 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
3131
*partrel - regclass (relation type, stored as Oid)
3232
*enable_parent - add parent table to plan
3333
*auto - enable automatic partition creation
34+
*init_callback - cb to be executed on partition creation
3435
*/
3536
CREATETABLEIF NOT EXISTS @extschema@.pathman_config_params (
3637
partrelREGCLASSNOT NULLPRIMARY KEY,
3738
enable_parentBOOLEANNOT NULL DEFAULT TRUE,
38-
autoBOOLEANNOT NULL DEFAULT TRUE
39+
autoBOOLEANNOT NULL DEFAULT TRUE,
40+
init_callbackREGPROCEDURENOT NULL DEFAULT0
3941
);
4042
CREATEUNIQUE INDEXi_pathman_config_params
4143
ON @extschema@.pathman_config_params(partrel);
@@ -85,15 +87,15 @@ BEGIN
8587
RETURNcount(*)FROM pg_inheritsWHERE inhparent= relation;
8688
END
8789
$$
88-
LANGUAGE plpgsql;
90+
LANGUAGE plpgsql STRICT;
8991

9092
/*
9193
* Add a row describing the optional parameter to pathman_config_params.
9294
*/
9395
CREATEOR REPLACE FUNCTION @extschema@.pathman_set_param(
9496
relationREGCLASS,
9597
paramTEXT,
96-
valueBOOLEAN)
98+
valueANYELEMENT)
9799
RETURNS VOIDAS
98100
$$
99101
BEGIN
@@ -106,49 +108,44 @@ $$
106108
LANGUAGE plpgsql;
107109

108110
/*
109-
* Include parent relation into query plan's for specified relation.
110-
*/
111-
CREATEOR REPLACE FUNCTION @extschema@.enable_parent(relation REGCLASS)
112-
RETURNS VOIDAS
113-
$$
114-
BEGIN
115-
PERFORM @extschema@.pathman_set_param(relation,'enable_parent', True);
116-
END
117-
$$
118-
LANGUAGE plpgsql;
119-
120-
/*
121-
* Do not include parent relation into query plan's for specified relation.
111+
* Include\exclude parent relation in query plan.
122112
*/
123-
CREATEOR REPLACE FUNCTION @extschema@.disable_parent(relation REGCLASS)
113+
CREATEOR REPLACE FUNCTION @extschema@.set_enable_parent(
114+
relationREGCLASS,
115+
valueBOOLEAN)
124116
RETURNS VOIDAS
125117
$$
126118
BEGIN
127-
PERFORM @extschema@.pathman_set_param(relation,'enable_parent',False);
119+
PERFORM @extschema@.pathman_set_param(relation,'enable_parent',value);
128120
END
129121
$$
130-
LANGUAGE plpgsql;
122+
LANGUAGE plpgsql STRICT;
131123

132124
/*
133-
* Enable automatic partition creation.
125+
* Enable\disable automatic partition creation.
134126
*/
135-
CREATEOR REPLACE FUNCTION @extschema@.enable_auto(relation REGCLASS)
127+
CREATEOR REPLACE FUNCTION @extschema@.set_auto(
128+
relationREGCLASS,
129+
valueBOOLEAN)
136130
RETURNS VOIDAS
137131
$$
138132
BEGIN
139-
PERFORM @extschema@.pathman_set_param(relation,'auto',True);
133+
PERFORM @extschema@.pathman_set_param(relation,'auto',value);
140134
END
141135
$$
142-
LANGUAGE plpgsql;
136+
LANGUAGE plpgsql STRICT;
143137

144138
/*
145-
*Disable automaticpartition creation.
139+
*Setpartition creation callback
146140
*/
147-
CREATEOR REPLACE FUNCTION @extschema@.disable_auto(relation REGCLASS)
141+
CREATEOR REPLACE FUNCTION @extschema@.set_part_init_callback(
142+
relationREGCLASS,
143+
callbackREGPROC)
148144
RETURNS VOIDAS
149145
$$
150146
BEGIN
151-
PERFORM @extschema@.pathman_set_param(relation,'auto', False);
147+
PERFORM @extschema@.validate_on_partition_created_callback(callback);
148+
PERFORM @extschema@.pathman_set_param(relation,'init_callback', callback);
152149
END
153150
$$
154151
LANGUAGE plpgsql;
@@ -201,6 +198,7 @@ DECLARE
201198
v_limit_clauseTEXT :='';
202199
v_where_clauseTEXT :='';
203200
ctidsTID[];
201+
204202
BEGIN
205203
SELECT attname INTO v_attr
206204
FROM @extschema@.pathman_configWHERE partrel= p_relation;
@@ -276,7 +274,7 @@ BEGIN
276274
RETURN;
277275
END
278276
$$
279-
LANGUAGE plpgsql
277+
LANGUAGE plpgsql STRICT
280278
SETpg_pathman.enable_partitionfilter=on;/* ensures that PartitionFilter is ON*/
281279

282280
/*
@@ -296,7 +294,7 @@ BEGIN
296294
PERFORM @extschema@.on_remove_partitions(parent_relid);
297295
END
298296
$$
299-
LANGUAGE plpgsql;
297+
LANGUAGE plpgsql STRICT;
300298

301299
/*
302300
* Aggregates several common relation checks before partitioning.
@@ -365,7 +363,7 @@ BEGIN
365363
INTO schema, relname;
366364
END
367365
$$
368-
LANGUAGE plpgsql;
366+
LANGUAGE plpgsql STRICT;
369367

370368
/*
371369
* Returns schema-qualified name for table
@@ -384,7 +382,7 @@ BEGIN
384382
WHEREoid= cls::oid);
385383
END
386384
$$
387-
LANGUAGE plpgsql;
385+
LANGUAGE plpgsql STRICT;
388386

389387
/*
390388
* Validates relation name. It must be schema qualified
@@ -484,7 +482,7 @@ BEGIN
484482
EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE',
485483
@extschema@.build_update_trigger_func_name(parent_relid));
486484
END
487-
$$ LANGUAGE plpgsql;
485+
$$ LANGUAGE plpgsql STRICT;
488486

489487
/*
490488
* Drop partitions
@@ -569,7 +567,7 @@ BEGIN
569567
pg_get_constraintdef(rec.conid));
570568
END LOOP;
571569
END
572-
$$ LANGUAGE plpgsql;
570+
$$ LANGUAGE plpgsql STRICT;
573571

574572

575573
/*
@@ -703,3 +701,41 @@ LANGUAGE C STRICT;
703701
CREATEOR REPLACE FUNCTION @extschema@.debug_capture()
704702
RETURNS VOIDAS'pg_pathman','debug_capture'
705703
LANGUAGE C STRICT;
704+
705+
/*
706+
* Return tablespace name for specified relation.
707+
*/
708+
CREATEOR REPLACE FUNCTION @extschema@.get_rel_tablespace_name(relation REGCLASS)
709+
RETURNSTEXTAS'pg_pathman','get_rel_tablespace_name'
710+
LANGUAGE C STRICT;
711+
712+
/*
713+
* Checks that callback function meets specific requirements. Particularly it
714+
* must have the only JSONB argument and VOID return type.
715+
*/
716+
CREATEOR REPLACE FUNCTION @extschema@.validate_on_partition_created_callback(callback REGPROC)
717+
RETURNS VOIDAS'pg_pathman','validate_on_part_init_callback_pl'
718+
LANGUAGE C STRICT;
719+
720+
721+
/*
722+
* Invoke init_callback on RANGE partition.
723+
*/
724+
CREATEOR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
725+
parent_relidREGCLASS,
726+
partitionREGCLASS,
727+
init_callbackREGPROCEDURE,
728+
start_valueANYELEMENT,
729+
end_valueANYELEMENT)
730+
RETURNS VOIDAS'pg_pathman','invoke_on_partition_created_callback'
731+
LANGUAGE C;
732+
733+
/*
734+
* Invoke init_callback on HASH partition.
735+
*/
736+
CREATEOR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
737+
parent_relidREGCLASS,
738+
partitionREGCLASS,
739+
init_callbackREGPROCEDURE)
740+
RETURNS VOIDAS'pg_pathman','invoke_on_partition_created_callback'
741+
LANGUAGE C;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp