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

Commit1385218

Browse files
committed
(performance) do not fetch PartRelationInfo in invoke_on_partition_created_callback(), rename callback -> init_callback, fixes
1 parentdfbbfeb commit1385218

File tree

9 files changed

+115
-113
lines changed

9 files changed

+115
-113
lines changed

‎expected/pg_pathman.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.set_auto_partitioning('test.range_rel', false);
1264-
set_auto_partitioning
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: There is no suitable partition for key 'Mon Jun 01 00:00:00 2015'
1271-
SELECT pathman.set_auto_partitioning('test.range_rel', true);
1272-
set_auto_partitioning
1273-
-----------------------
1271+
SELECT pathman.set_auto('test.range_rel', true);
1272+
set_auto
1273+
----------
12741274

12751275
(1 row)
12761276

‎hash.sql

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ DECLARE
2424
v_plain_schemaTEXT;
2525
v_plain_relnameTEXT;
2626
v_hashfuncTEXT;
27-
v_tablespaceTEXT;
27+
v_init_callbackREGPROCEDURE;
2828

2929
BEGIN
3030
IF partition_data= true THEN
@@ -50,9 +50,6 @@ BEGIN
5050
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype)
5151
VALUES (parent_relid, attribute,1);
5252

53-
/* Determine tablespace of parent table*/
54-
v_tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
55-
5653
/* Create partitions and update pg_pathman configuration*/
5754
FOR partnumIN0..partitions_count-1
5855
LOOP
@@ -64,7 +61,7 @@ BEGIN
6461
'CREATE TABLE %1$s (LIKE %2$s INCLUDING ALL) INHERITS (%2$s) TABLESPACE %s',
6562
v_child_relname,
6663
parent_relid::TEXT,
67-
v_tablespace);
64+
@extschema@.get_rel_tablespace_name(parent_relid));
6865

6966
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s
7067
CHECK (@extschema@.get_hash_part_idx(%s(%s), %s) = %s)',
@@ -77,6 +74,18 @@ BEGIN
7774
partnum);
7875

7976
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);
8089
END LOOP;
8190

8291
/* Notify backend about changes*/

‎init.sql

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ LANGUAGE plpgsql STRICT;
124124
/*
125125
* Enable\disable automatic partition creation.
126126
*/
127-
CREATEOR REPLACE FUNCTION @extschema@.set_auto_partitioning(
127+
CREATEOR REPLACE FUNCTION @extschema@.set_auto(
128128
relationREGCLASS,
129129
valueBOOLEAN)
130130
RETURNS VOIDAS
@@ -713,6 +713,16 @@ LANGUAGE C STRICT;
713713
*/
714714
CREATEOR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
715715
parent_relidREGCLASS,
716-
partitionREGCLASS)
717-
RETURNS JSONBAS'pg_pathman','invoke_on_partition_created_callback'
716+
partitionREGCLASS,
717+
init_callbackREGPROCEDURE,
718+
start_valueANYELEMENT,
719+
end_valueANYELEMENT)
720+
RETURNS VOIDAS'pg_pathman','invoke_on_partition_created_callback'
721+
LANGUAGE C;
722+
723+
CREATEOR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
724+
parent_relidREGCLASS,
725+
partitionREGCLASS,
726+
init_callbackREGPROCEDURE)
727+
RETURNS VOIDAS'pg_pathman','invoke_on_partition_created_callback'
718728
LANGUAGE C;

‎range.sql

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ CREATE OR REPLACE FUNCTION @extschema@.create_range_partitions(
8484
p_start_valueANYELEMENT,
8585
p_intervalINTERVAL,
8686
p_countINTEGER DEFAULTNULL,
87-
partition_dataBOOLEAN DEFAULTtrue)
87+
partition_dataBOOLEAN DEFAULTTRUE)
8888
RETURNSINTEGERAS
8989
$$
9090
DECLARE
9191
v_rows_countINTEGER;
9292
v_maxp_start_value%TYPE;
9393
v_cur_valuep_start_value%TYPE := p_start_value;
94-
v_tablespaceTEXT;
9594
iINTEGER;
95+
9696
BEGIN
9797
IF partition_data= true THEN
9898
/* Acquire data modification lock*/
@@ -149,9 +149,6 @@ BEGIN
149149
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype, range_interval)
150150
VALUES (parent_relid, p_attribute,2, p_interval::TEXT);
151151

152-
/* Determine tablespace of parent table*/
153-
v_tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
154-
155152
/* Create first partition*/
156153
FOR iIN1..p_count
157154
LOOP
@@ -162,7 +159,7 @@ BEGIN
162159
parent_relid,
163160
p_start_value,
164161
p_start_value+ p_interval,
165-
v_tablespace;
162+
@extschema@.get_rel_tablespace_name(parent_relid);
166163

167164
p_start_value := p_start_value+ p_interval;
168165
END LOOP;
@@ -191,14 +188,13 @@ CREATE OR REPLACE FUNCTION @extschema@.create_range_partitions(
191188
p_start_valueANYELEMENT,
192189
p_intervalANYELEMENT,
193190
p_countINTEGER DEFAULTNULL,
194-
partition_dataBOOLEAN DEFAULTtrue)
191+
partition_dataBOOLEAN DEFAULTTRUE)
195192
RETURNSINTEGERAS
196193
$$
197194
DECLARE
198195
v_rows_countINTEGER;
199196
v_maxp_start_value%TYPE;
200197
v_cur_valuep_start_value%TYPE := p_start_value;
201-
v_tablespaceTEXT;
202198
iINTEGER;
203199

204200
BEGIN
@@ -259,17 +255,14 @@ BEGIN
259255
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype, range_interval)
260256
VALUES (parent_relid, p_attribute,2, p_interval::TEXT);
261257

262-
/* Determine tablespace of parent table*/
263-
v_tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
264-
265258
/* create first partition*/
266259
FOR iIN1..p_count
267260
LOOP
268261
PERFORM @extschema@.create_single_range_partition(
269262
parent_relid,
270263
p_start_value,
271264
p_start_value+ p_interval,
272-
tablespace :=v_tablespace);
265+
tablespace :=@extschema@.get_rel_tablespace_name(parent_relid));
273266

274267
p_start_value := p_start_value+ p_interval;
275268
END LOOP;
@@ -298,12 +291,11 @@ CREATE OR REPLACE FUNCTION @extschema@.create_partitions_from_range(
298291
p_start_valueANYELEMENT,
299292
p_end_valueANYELEMENT,
300293
p_intervalANYELEMENT,
301-
partition_dataBOOLEAN DEFAULTtrue)
294+
partition_dataBOOLEAN DEFAULTTRUE)
302295
RETURNSINTEGERAS
303296
$$
304297
DECLARE
305298
part_countINTEGER :=0;
306-
v_tablespaceTEXT;
307299

308300
BEGIN
309301
IF partition_data= true THEN
@@ -336,16 +328,13 @@ BEGIN
336328
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype, range_interval)
337329
VALUES (parent_relid, p_attribute,2, p_interval::TEXT);
338330

339-
/* Determine tablespace of parent table*/
340-
v_tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
341-
342331
WHILE p_start_value<= p_end_value
343332
LOOP
344333
PERFORM @extschema@.create_single_range_partition(
345334
parent_relid,
346335
p_start_value,
347336
p_start_value+ p_interval,
348-
tablespace :=v_tablespace);
337+
tablespace :=@extschema@.get_rel_tablespace_name(parent_relid));
349338

350339
p_start_value := p_start_value+ p_interval;
351340
part_count := part_count+1;
@@ -375,12 +364,11 @@ CREATE OR REPLACE FUNCTION @extschema@.create_partitions_from_range(
375364
p_start_valueANYELEMENT,
376365
p_end_valueANYELEMENT,
377366
p_intervalINTERVAL,
378-
partition_dataBOOLEAN DEFAULTtrue)
367+
partition_dataBOOLEAN DEFAULTTRUE)
379368
RETURNSINTEGERAS
380369
$$
381370
DECLARE
382371
part_countINTEGER :=0;
383-
v_tablespaceTEXT;
384372

385373
BEGIN
386374
IF partition_data= true THEN
@@ -409,9 +397,6 @@ BEGIN
409397
INSERT INTO @extschema@.pathman_config (partrel, attname, parttype, range_interval)
410398
VALUES (parent_relid, p_attribute,2, p_interval::TEXT);
411399

412-
/* Determine tablespace of parent table*/
413-
v_tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
414-
415400
WHILE p_start_value<= p_end_value
416401
LOOP
417402
EXECUTE
@@ -421,7 +406,7 @@ BEGIN
421406
parent_relid,
422407
p_start_value,
423408
p_start_value+ p_interval,
424-
v_tablespace;
409+
@extschema@.get_rel_tablespace_name(parent_relid);
425410

426411
p_start_value := p_start_value+ p_interval;
427412
part_count := part_count+1;
@@ -463,7 +448,8 @@ DECLARE
463448
v_plain_relnameTEXT;
464449
v_child_relname_existsBOOL;
465450
v_seq_nameTEXT;
466-
v_create_table_queryTEXT;
451+
v_init_callbackREGPROCEDURE;
452+
467453
BEGIN
468454
v_attname := attnameFROM @extschema@.pathman_config
469455
WHERE partrel= parent_relid;
@@ -498,16 +484,15 @@ BEGIN
498484
v_child_relname := partition_name;
499485
END IF;
500486

501-
v_create_table_query :='CREATE TABLE %1$s (LIKE %2$s INCLUDING ALL) INHERITS (%2$s)';
502-
503-
/* If tablespace is specified then add it to a create query*/
504-
if NOT tablespace ISNULL THEN
505-
v_create_table_query := v_create_table_query||' TABLESPACE'||tablespace;
487+
IF tablespace ISNULL THEN
488+
tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
506489
END IF;
507490

508-
EXECUTE format(v_create_table_query,
491+
EXECUTE format('CREATE TABLE %1$s (LIKE %2$s INCLUDING ALL)
492+
INHERITS (%2$s) TABLESPACE %3$s',
509493
v_child_relname,
510-
parent_relid::TEXT);
494+
parent_relid::TEXT,
495+
tablespace);
511496

512497
EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s)',
513498
v_child_relname,
@@ -518,8 +503,20 @@ BEGIN
518503
p_end_value));
519504

520505
PERFORM @extschema@.copy_foreign_keys(parent_relid, v_child_relname::REGCLASS);
506+
507+
/* Fetch init_callback from 'params' table*/
508+
WITH stub_callback(stub)as (values (0))
509+
SELECT coalesce(init_callback,0::REGPROCEDURE)
510+
FROM stub_callback
511+
LEFT JOIN @extschema@.pathman_config_paramsAS params
512+
ONparams.partrel= parent_relid
513+
INTO v_init_callback;
514+
521515
PERFORM @extschema@.invoke_on_partition_created_callback(parent_relid,
522-
v_child_relname::REGCLASS);
516+
v_child_relname::REGCLASS,
517+
v_init_callback,
518+
p_start_value,
519+
p_end_value);
523520

524521
RETURN v_child_relname;
525522
END
@@ -817,11 +814,6 @@ BEGIN
817814
RAISE EXCEPTION'Cannot append to empty partitions set';
818815
END IF;
819816

820-
/* If tablespace isn't specified then choose parent's tablespace*/
821-
IF tablespace ISNULL THEN
822-
tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
823-
END IF;
824-
825817
p_range := @extschema@.get_range_by_idx(parent_relid,-1,0);
826818

827819
IF @extschema@.is_date_type(p_atttype::regtype) THEN
@@ -922,11 +914,6 @@ BEGIN
922914
RAISE EXCEPTION'Cannot prepend to empty partitions set';
923915
END IF;
924916

925-
/* If tablespace isn't specified then choose parent's tablespace*/
926-
IF tablespace ISNULL THEN
927-
tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
928-
END IF;
929-
930917
p_range := @extschema@.get_range_by_idx(parent_relid,0,0);
931918

932919
IF @extschema@.is_date_type(p_atttype::regtype) THEN
@@ -985,11 +972,6 @@ BEGIN
985972
RAISE EXCEPTION'Specified range overlaps with existing partitions';
986973
END IF;
987974

988-
/* If tablespace isn't specified then choose parent's tablespace*/
989-
IF tablespace ISNULL THEN
990-
tablespace := @extschema@.get_rel_tablespace_name(parent_relid);
991-
END IF;
992-
993975
/* Create new partition*/
994976
v_part_name := @extschema@.create_single_range_partition(parent_relid,
995977
p_start_value,

‎sql/pg_pathman.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ SELECT * FROM test.range_rel WHERE dt = '2014-12-15';
525525
EXPLAIN (COSTS OFF)SELECT*FROMtest.range_relWHERE dt='2015-03-15';
526526
SELECT*FROMtest.range_relWHERE dt='2015-03-15';
527527

528-
SELECTpathman.set_auto_partitioning('test.range_rel', false);
528+
SELECTpathman.set_auto('test.range_rel', false);
529529
INSERT INTOtest.range_rel (dt)VALUES ('2015-06-01');
530-
SELECTpathman.set_auto_partitioning('test.range_rel', true);
530+
SELECTpathman.set_auto('test.range_rel', true);
531531
INSERT INTOtest.range_rel (dt)VALUES ('2015-06-01');
532532

533533
DROPTABLEtest.range_rel CASCADE;

‎src/init.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
661661
/* Extract data if necessary */
662662
heap_deform_tuple(htup,RelationGetDescr(rel),values,isnull);
663663
row_found= true;
664+
665+
/* Perform checks for non-NULL columns */
666+
Assert(!isnull[Anum_pathman_config_params_partrel-1]);
667+
Assert(!isnull[Anum_pathman_config_params_enable_parent-1]);
668+
Assert(!isnull[Anum_pathman_config_params_auto-1]);
669+
Assert(!isnull[Anum_pathman_config_params_init_callback-1]);
664670
}
665671

666672
/* Clean resources */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp