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

Commitded87de

Browse files
committed
rewrited drop_triggers() func and tests are fixed
1 parentdd01513 commitded87de

9 files changed

+68
-84
lines changed

‎expected/pathman_basic.out

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ SELECT * FROM test.hash_rel;
8181
(3 rows)
8282

8383
SELECT pathman.drop_partitions('test.hash_rel');
84-
NOTICE: function test.hash_rel_upd_trig_func() does not exist, skipping
8584
NOTICE: 0 rows copied from test.hash_rel_0
8685
NOTICE: 0 rows copied from test.hash_rel_1
8786
NOTICE: 0 rows copied from test.hash_rel_2
@@ -570,10 +569,10 @@ SET pg_pathman.enable_runtimeappend = OFF;
570569
SET pg_pathman.enable_runtimemergeappend = OFF;
571570
VACUUM;
572571
/* update triggers test */
573-
SELECT pathman.create_hash_update_trigger('test.hash_rel');
574-
create_hash_update_trigger
575-
-----------------------------
576-
test.hash_rel_upd_trig_func
572+
SELECT pathman.create_update_triggers('test.hash_rel');
573+
create_update_triggers
574+
------------------------
575+
577576
(1 row)
578577

579578
UPDATE test.hash_rel SET value = 7 WHERE value = 6;
@@ -591,10 +590,10 @@ SELECT * FROM test.hash_rel WHERE value = 7;
591590
6 | 7
592591
(1 row)
593592

594-
SELECT pathman.create_range_update_trigger('test.num_range_rel');
595-
create_range_update_trigger
596-
----------------------------------
597-
test.num_range_rel_upd_trig_func
593+
SELECT pathman.create_update_triggers('test.num_range_rel');
594+
create_update_triggers
595+
------------------------
596+
598597
(1 row)
599598

600599
UPDATE test.num_range_rel SET id = 3001 WHERE id = 1;
@@ -1477,7 +1476,7 @@ SELECT pathman.replace_hash_partition('test.hash_rel_0', 'test.hash_rel_extern')
14771476
Indexes:
14781477
"hash_rel_0_pkey" PRIMARY KEY, btree (id)
14791478
Triggers:
1480-
hash_rel_upd_trig BEFORE UPDATE ON test.hash_rel_0 FOR EACH ROW EXECUTE PROCEDUREtest.hash_rel_upd_trig_func()
1479+
hash_rel_upd_trig BEFORE UPDATE ON test.hash_rel_0 FOR EACH ROW EXECUTE PROCEDUREpathman.update_trigger_func()
14811480

14821481
\d+ test.hash_rel_extern
14831482
Table "test.hash_rel_extern"
@@ -1513,7 +1512,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.hash_rel;
15131512
* Clean up
15141513
*/
15151514
SELECT pathman.drop_partitions('test.hash_rel');
1516-
NOTICE: drop cascades to 2 other objects
15171515
NOTICE: 3 rows copied from test.hash_rel_1
15181516
NOTICE: 2 rows copied from test.hash_rel_2
15191517
NOTICE: 2 rows copied from test.hash_rel_extern
@@ -1535,7 +1533,6 @@ SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3);
15351533
(1 row)
15361534

15371535
SELECT pathman.drop_partitions('test.hash_rel', TRUE);
1538-
NOTICE: function test.hash_rel_upd_trig_func() does not exist, skipping
15391536
drop_partitions
15401537
-----------------
15411538
3
@@ -1549,7 +1546,6 @@ SELECT COUNT(*) FROM ONLY test.hash_rel;
15491546

15501547
DROP TABLE test.hash_rel CASCADE;
15511548
SELECT pathman.drop_partitions('test.num_range_rel');
1552-
NOTICE: drop cascades to 3 other objects
15531549
NOTICE: 998 rows copied from test.num_range_rel_1
15541550
NOTICE: 1000 rows copied from test.num_range_rel_2
15551551
NOTICE: 1000 rows copied from test.num_range_rel_3
@@ -1690,10 +1686,10 @@ SELECT * FROM test."TeSt";
16901686
1 | 1
16911687
(3 rows)
16921688

1693-
SELECT pathman.create_hash_update_trigger('test."TeSt"');
1694-
create_hash_update_trigger
1695-
----------------------------
1696-
test."TeSt_upd_trig_func"
1689+
SELECT pathman.create_update_triggers('test."TeSt"');
1690+
create_update_triggers
1691+
------------------------
1692+
16971693
(1 row)
16981694

16991695
UPDATE test."TeSt" SET a = 1;
@@ -1722,7 +1718,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM test."TeSt" WHERE a = 1;
17221718
(3 rows)
17231719

17241720
SELECT pathman.drop_partitions('test."TeSt"');
1725-
NOTICE: drop cascades to 3 other objects
17261721
NOTICE: 0 rows copied from test."TeSt_0"
17271722
NOTICE: 0 rows copied from test."TeSt_1"
17281723
NOTICE: 3 rows copied from test."TeSt_2"
@@ -1777,7 +1772,6 @@ SELECT pathman.split_range_partition('test."RangeRel_1"', '2015-01-01'::DATE);
17771772
(1 row)
17781773

17791774
SELECT pathman.drop_partitions('test."RangeRel"');
1780-
NOTICE: function test.RangeRel_upd_trig_func() does not exist, skipping
17811775
NOTICE: 0 rows copied from test."RangeRel_1"
17821776
NOTICE: 1 rows copied from test."RangeRel_2"
17831777
NOTICE: 1 rows copied from test."RangeRel_3"
@@ -1813,7 +1807,6 @@ SELECT pathman.create_range_partitions('test."RangeRel"', 'id', 1, 100, 3);
18131807
(1 row)
18141808

18151809
SELECT pathman.drop_partitions('test."RangeRel"');
1816-
NOTICE: function test.RangeRel_upd_trig_func() does not exist, skipping
18171810
NOTICE: 0 rows copied from test."RangeRel_1"
18181811
NOTICE: 0 rows copied from test."RangeRel_2"
18191812
NOTICE: 0 rows copied from test."RangeRel_3"
@@ -1971,7 +1964,6 @@ EXPLAIN (COSTS OFF) DELETE FROM test.range_rel r USING test.tmp t WHERE r.dt = '
19711964
DELETE FROM test.range_rel r USING test.tmp t WHERE r.dt = '2010-01-02' AND r.id = t.id;
19721965
/* Create range partitions from whole range */
19731966
SELECT drop_partitions('test.range_rel');
1974-
NOTICE: function test.range_rel_upd_trig_func() does not exist, skipping
19751967
NOTICE: 44 rows copied from test.range_rel_1
19761968
NOTICE: 31 rows copied from test.range_rel_3
19771969
NOTICE: 30 rows copied from test.range_rel_4
@@ -1998,7 +1990,6 @@ SELECT create_partitions_from_range('test.range_rel', 'id', 1, 1000, 100);
19981990
(1 row)
19991991

20001992
SELECT drop_partitions('test.range_rel', TRUE);
2001-
NOTICE: function test.range_rel_upd_trig_func() does not exist, skipping
20021993
drop_partitions
20031994
-----------------
20041995
10

‎expected/pathman_calamity.out

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ NOTICE: sequence "part_test_seq" does not exist, skipping
2828
(1 row)
2929

3030
SELECT drop_partitions('calamity.part_test');
31-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
3231
NOTICE: 10 rows copied from calamity.part_test_1
3332
NOTICE: 10 rows copied from calamity.part_test_2
3433
NOTICE: 10 rows copied from calamity.part_test_3
@@ -44,7 +43,6 @@ SELECT create_range_partitions('calamity.part_test', 'val', 1, 10);
4443
(1 row)
4544

4645
SELECT drop_partitions('calamity.part_test');
47-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
4846
NOTICE: 10 rows copied from calamity.part_test_1
4947
NOTICE: 10 rows copied from calamity.part_test_2
5048
NOTICE: 10 rows copied from calamity.part_test_3
@@ -66,7 +64,6 @@ SELECT append_range_partition('calamity.part_test');
6664
(1 row)
6765

6866
SELECT drop_partitions('calamity.part_test');
69-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
7067
NOTICE: 10 rows copied from calamity.part_test_1
7168
NOTICE: 10 rows copied from calamity.part_test_2
7269
NOTICE: 10 rows copied from calamity.part_test_3
@@ -89,7 +86,6 @@ SELECT append_range_partition('calamity.part_test');
8986
(1 row)
9087

9188
SELECT drop_partitions('calamity.part_test');
92-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
9389
NOTICE: 10 rows copied from calamity.part_test_1
9490
NOTICE: 10 rows copied from calamity.part_test_2
9591
NOTICE: 10 rows copied from calamity.part_test_3
@@ -171,7 +167,6 @@ EXPLAIN (COSTS OFF) SELECT * FROM calamity.part_test;
171167
(5 rows)
172168

173169
SELECT drop_partitions('calamity.part_test', true);
174-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
175170
drop_partitions
176171
-----------------
177172
4
@@ -199,7 +194,6 @@ ERROR: invalid input syntax for integer: "15.6"
199194
SELECT set_interval('calamity.part_test', 'abc'::text);/* not ok */
200195
ERROR: invalid input syntax for integer: "abc"
201196
SELECT drop_partitions('calamity.part_test', true);
202-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
203197
drop_partitions
204198
-----------------
205199
3
@@ -479,7 +473,6 @@ SELECT add_to_pathman_config('calamity.part_test', 'val');/* OK */
479473
(1 row)
480474

481475
SELECT disable_pathman_for('calamity.part_test');
482-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
483476
disable_pathman_for
484477
---------------------
485478

@@ -492,7 +485,6 @@ SELECT add_to_pathman_config('calamity.part_test', 'val', '10'); /* OK */
492485
(1 row)
493486

494487
SELECT disable_pathman_for('calamity.part_test');
495-
NOTICE: function calamity.part_test_upd_trig_func() does not exist, skipping
496488
disable_pathman_for
497489
---------------------
498490

@@ -599,7 +591,6 @@ SELECT set_enable_parent('calamity.to_be_disabled', true); /* add row to params
599591
(1 row)
600592

601593
SELECT disable_pathman_for('calamity.to_be_disabled'); /* should delete both rows */
602-
NOTICE: function calamity.to_be_disabled_upd_trig_func() does not exist, skipping
603594
disable_pathman_for
604595
---------------------
605596

‎expected/pathman_callbacks.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ WARNING: callback arg: {"parent": "abc", "parttype": "2", "partition": "abc_7",
133133
(1 row)
134134

135135
SELECT drop_partitions('callbacks.abc');
136-
NOTICE: function callbacks.abc_upd_trig_func() does not exist, skipping
137136
NOTICE: 0 rows copied from callbacks.abc_1
138137
NOTICE: 1 rows copied from callbacks.abc_2
139138
NOTICE: 1 rows copied from callbacks.abc_3

‎expected/pathman_cte.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ WHERE t.id = tmp.tid AND t.pdate = tmp.pdate AND tmp.test_mode > 0;
121121
(24 rows)
122122

123123
SELECT drop_partitions('test_cte.cte_del_xacts'); /* now drop partitions */
124-
NOTICE: function test_cte.cte_del_xacts_upd_trig_func() does not exist, skipping
125124
NOTICE: 50 rows copied from test_cte.cte_del_xacts_1
126125
NOTICE: 50 rows copied from test_cte.cte_del_xacts_2
127126
drop_partitions

‎expected/pathman_domains.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ ORDER BY range_min::INT, range_max::INT;
8888
(14 rows)
8989

9090
SELECT drop_partitions('domains.dom_table');
91-
NOTICE: function domains.dom_table_upd_trig_func() does not exist, skipping
9291
NOTICE: 49 rows copied from domains.dom_table_1
9392
NOTICE: 100 rows copied from domains.dom_table_3
9493
NOTICE: 100 rows copied from domains.dom_table_4

‎expected/pathman_foreign_keys.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ INSERT INTO fkeys.test_fkey VALUES(1, 'wrong');
2020
ERROR: insert or update on table "test_fkey_1" violates foreign key constraint "test_fkey_1_comment_fkey"
2121
INSERT INTO fkeys.test_fkey VALUES(1, 'test');
2222
SELECT drop_partitions('fkeys.test_fkey');
23-
NOTICE: function fkeys.test_fkey_upd_trig_func() does not exist, skipping
2423
NOTICE: 101 rows copied from fkeys.test_fkey_1
2524
NOTICE: 100 rows copied from fkeys.test_fkey_2
2625
NOTICE: 100 rows copied from fkeys.test_fkey_3
@@ -46,7 +45,6 @@ INSERT INTO fkeys.test_fkey VALUES(1, 'wrong');
4645
ERROR: insert or update on table "test_fkey_0" violates foreign key constraint "test_fkey_0_comment_fkey"
4746
INSERT INTO fkeys.test_fkey VALUES(1, 'test');
4847
SELECT drop_partitions('fkeys.test_fkey');
49-
NOTICE: function fkeys.test_fkey_upd_trig_func() does not exist, skipping
5048
NOTICE: 100 rows copied from fkeys.test_fkey_0
5149
NOTICE: 90 rows copied from fkeys.test_fkey_1
5250
NOTICE: 90 rows copied from fkeys.test_fkey_2

‎expected/pathman_permissions.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ ERROR: no suitable partition for key '55'
134134
/* Finally drop partitions */
135135
SET ROLE user1;
136136
SELECT drop_partitions('permissions.user1_table');
137-
NOTICE: function permissions.user1_table_upd_trig_func() does not exist, skipping
138137
NOTICE: 10 rows copied from permissions.user1_table_1
139138
NOTICE: 10 rows copied from permissions.user1_table_2
140139
NOTICE: 0 rows copied from permissions.user1_table_4
@@ -157,7 +156,6 @@ SELECT create_hash_partitions('permissions.user2_table', 'id', 3);
157156

158157
INSERT INTO permissions.user2_table SELECT generate_series(1, 30);
159158
SELECT drop_partitions('permissions.user2_table');
160-
NOTICE: function permissions.user2_table_upd_trig_func() does not exist, skipping
161159
NOTICE: 9 rows copied from permissions.user2_table_0
162160
NOTICE: 11 rows copied from permissions.user2_table_1
163161
NOTICE: 10 rows copied from permissions.user2_table_2

‎init.sql

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -551,15 +551,64 @@ $$
551551
LANGUAGE plpgsql;
552552

553553
/*
554-
* Drop triggers.
554+
* Function for update triggers
555+
*/
556+
CREATEOR REPLACE FUNCTION @extschema@.update_trigger_func()
557+
RETURNS TRIGGERAS'pg_pathman','update_trigger_func'
558+
LANGUAGE C;
559+
560+
/*
561+
* Creates an update trigger
562+
*/
563+
CREATEOR REPLACE FUNCTION @extschema@.create_update_triggers(
564+
IN parent_relidREGCLASS)
565+
RETURNS VOIDAS
566+
$$
567+
DECLARE
568+
triggerTEXT :='CREATE TRIGGER %s
569+
BEFORE UPDATE ON %s
570+
FOR EACH ROW EXECUTE PROCEDURE
571+
@extschema@.update_trigger_func()';
572+
triggernameTEXT;
573+
recRECORD;
574+
575+
BEGIN
576+
triggername := @extschema@.build_update_trigger_name(parent_relid);
577+
578+
/* Create trigger on every partition*/
579+
FOR recin (SELECT*FROMpg_catalog.pg_inherits
580+
WHERE inhparent= parent_relid)
581+
LOOP
582+
EXECUTE format(trigger,
583+
triggername,
584+
rec.inhrelid::REGCLASS::TEXT);
585+
END LOOP;
586+
END
587+
$$ LANGUAGE plpgsql;
588+
589+
/*
590+
* Drop triggers
555591
*/
556592
CREATEOR REPLACE FUNCTION @extschema@.drop_triggers(
557593
parent_relidREGCLASS)
558594
RETURNS VOIDAS
559595
$$
596+
DECLARE
597+
triggernameTEXT;
598+
recRECORD;
599+
560600
BEGIN
561-
EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE',
562-
@extschema@.build_update_trigger_func_name(parent_relid));
601+
triggername := @extschema@.build_update_trigger_name(parent_relid);
602+
603+
/* Drop trigger for each partition if exists*/
604+
FOR recIN (SELECTpg_catalog.pg_inherits.*FROMpg_catalog.pg_inherits
605+
JOINpg_catalog.pg_triggeron inhrelid= tgrelid
606+
WHERE inhparent= parent_relidAND tgname= triggername)
607+
LOOP
608+
EXECUTE format('DROP TRIGGER IF EXISTS %s ON %s',
609+
triggername,
610+
rec.inhrelid::REGCLASS::TEXT);
611+
END LOOP;
563612
END
564613
$$ LANGUAGE plpgsql STRICT;
565614

@@ -896,43 +945,3 @@ CREATE OR REPLACE FUNCTION @extschema@.invoke_on_partition_created_callback(
896945
init_callbackREGPROCEDURE)
897946
RETURNS VOIDAS'pg_pathman','invoke_on_partition_created_callback'
898947
LANGUAGE C;
899-
900-
901-
/*
902-
* Function for update triggers
903-
*/
904-
CREATEOR REPLACE FUNCTION @extschema@.update_trigger_func()
905-
RETURNS TRIGGERAS'pg_pathman','update_trigger_func'
906-
LANGUAGE C;
907-
908-
909-
/*
910-
* Creates an update trigger
911-
*/
912-
CREATEOR REPLACE FUNCTION @extschema@.create_update_trigger(
913-
IN parent_relidREGCLASS)
914-
RETURNSTEXTAS
915-
$$
916-
DECLARE
917-
triggerTEXT :='CREATE TRIGGER %s
918-
BEFORE UPDATE ON %s
919-
FOR EACH ROW EXECUTE PROCEDURE
920-
@extschema@.update_trigger_func()';
921-
triggernameTEXT;
922-
recRECORD;
923-
924-
BEGIN
925-
triggername := @extschema@.build_update_trigger_name(parent_relid);
926-
927-
/* Create trigger on every partition*/
928-
FOR recin (SELECT*FROMpg_catalog.pg_inherits
929-
WHERE inhparent= parent_relid)
930-
LOOP
931-
EXECUTE format(trigger,
932-
triggername,
933-
rec.inhrelid::REGCLASS::TEXT);
934-
END LOOP;
935-
936-
RETURN'update_trigger_func()';
937-
END
938-
$$ LANGUAGE plpgsql;

‎sql/pathman_basic.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ SET pg_pathman.enable_runtimemergeappend = OFF;
173173
VACUUM;
174174

175175
/* update triggers test*/
176-
SELECTpathman.create_hash_update_trigger('test.hash_rel');
176+
SELECTpathman.create_update_triggers('test.hash_rel');
177177
UPDATEtest.hash_relSET value=7WHERE value=6;
178178
EXPLAIN (COSTS OFF)SELECT*FROMtest.hash_relWHERE value=7;
179179
SELECT*FROMtest.hash_relWHERE value=7;
180180

181-
SELECTpathman.create_range_update_trigger('test.num_range_rel');
181+
SELECTpathman.create_update_triggers('test.num_range_rel');
182182
UPDATEtest.num_range_relSET id=3001WHERE id=1;
183183
EXPLAIN (COSTS OFF)SELECT*FROMtest.num_range_relWHERE id=3001;
184184
SELECT*FROMtest.num_range_relWHERE id=3001;
@@ -464,7 +464,7 @@ INSERT INTO test."TeSt" VALUES (1, 1);
464464
INSERT INTO test."TeSt"VALUES (2,2);
465465
INSERT INTO test."TeSt"VALUES (3,3);
466466
SELECT*FROM test."TeSt";
467-
SELECTpathman.create_hash_update_trigger('test."TeSt"');
467+
SELECTpathman.create_update_triggers('test."TeSt"');
468468
UPDATE test."TeSt"SET a=1;
469469
SELECT*FROM test."TeSt";
470470
SELECT*FROM test."TeSt"WHERE a=1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp