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

Commit1637d95

Browse files
committed
Propagate trigger arguments to partitions
We were creating the cloned triggers with an empty list of arguments,losing the ones that had been specified by the user when creating thetrigger in the partitioned table. Repair.This was forgotten in commit86f5759.Author: Patrick McHardyReviewed-by: Tomas VondraDiscussion:https://postgr.es/m/20190709130027.amr2cavjvo7rdvac@access1.trash.netDiscussion:https://postgr.es/m/15752-123bc90287986de4@postgresql.org
1 parent3955c50 commit1637d95

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15202,6 +15202,7 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
1520215202
Datumvalue;
1520315203
boolisnull;
1520415204
List*cols=NIL;
15205+
List*trigargs=NIL;
1520515206
MemoryContextoldcxt;
1520615207

1520715208
/*
@@ -15266,11 +15267,31 @@ CloneRowTriggersToPartition(Relation parent, Relation partition)
1526615267
}
1526715268
}
1526815269

15270+
/* Reconstruct trigger arguments list. */
15271+
if (trigForm->tgnargs>0)
15272+
{
15273+
char*p;
15274+
15275+
value=heap_getattr(tuple,Anum_pg_trigger_tgargs,
15276+
RelationGetDescr(pg_trigger),&isnull);
15277+
if (isnull)
15278+
elog(ERROR,"tgargs is null for trigger \"%s\" in partition \"%s\"",
15279+
NameStr(trigForm->tgname),RelationGetRelationName(partition));
15280+
15281+
p= (char*)VARDATA_ANY(DatumGetByteaPP(value));
15282+
15283+
for (inti=0;i<trigForm->tgnargs;i++)
15284+
{
15285+
trigargs=lappend(trigargs,makeString(pstrdup(p)));
15286+
p+=strlen(p)+1;
15287+
}
15288+
}
15289+
1526915290
trigStmt=makeNode(CreateTrigStmt);
1527015291
trigStmt->trigname=NameStr(trigForm->tgname);
1527115292
trigStmt->relation=NULL;
1527215293
trigStmt->funcname=NULL;/* passed separately */
15273-
trigStmt->args=NULL;/* passed separately */
15294+
trigStmt->args=trigargs;
1527415295
trigStmt->row= true;
1527515296
trigStmt->timing=trigForm->tgtype&TRIGGER_TYPE_TIMING_MASK;
1527615297
trigStmt->events=trigForm->tgtype&TRIGGER_TYPE_EVENT_MASK;

‎src/backend/commands/trigger.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,6 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
11531153
*/
11541154
childStmt= (CreateTrigStmt*)copyObject(stmt);
11551155
childStmt->funcname=NIL;
1156-
childStmt->args=NIL;
11571156
childStmt->whenClause=NULL;
11581157

11591158
/* If there is a WHEN clause, create a modified copy of it */

‎src/test/regress/expected/triggers.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,30 @@ NOTICE: trigger zzz on parted_trig_1_1 AFTER INSERT for ROW
20922092
NOTICE: trigger bbb on parted_trig_2 AFTER INSERT for ROW
20932093
NOTICE: trigger zzz on parted_trig_2 AFTER INSERT for ROW
20942094
drop table parted_trig;
2095+
-- Verify propagation of trigger arguments to partitions
2096+
create table parted_trig (a int) partition by list (a);
2097+
create table parted_trig1 partition of parted_trig for values in (1);
2098+
create or replace function trigger_notice() returns trigger as $$
2099+
declare
2100+
arg1 text = TG_ARGV[0];
2101+
arg2 integer = TG_ARGV[1];
2102+
begin
2103+
raise notice 'trigger % on % % % for % args % %',
2104+
TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, arg1, arg2;
2105+
return null;
2106+
end;
2107+
$$ language plpgsql;
2108+
create trigger aaa after insert on parted_trig
2109+
for each row execute procedure trigger_notice('quirky', 1);
2110+
-- Verify propagation of trigger arguments to partitions attached after creating trigger
2111+
create table parted_trig2 partition of parted_trig for values in (2);
2112+
create table parted_trig3 (like parted_trig);
2113+
alter table parted_trig attach partition parted_trig3 for values in (3);
2114+
insert into parted_trig values (1), (2), (3);
2115+
NOTICE: trigger aaa on parted_trig1 AFTER INSERT for ROW args quirky 1
2116+
NOTICE: trigger aaa on parted_trig2 AFTER INSERT for ROW args quirky 1
2117+
NOTICE: trigger aaa on parted_trig3 AFTER INSERT for ROW args quirky 1
2118+
drop table parted_trig;
20952119
-- test irregular partitions (i.e., different column definitions),
20962120
-- including that the WHEN clause works
20972121
create function bark(text) returns bool language plpgsql immutable

‎src/test/regress/sql/triggers.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,29 @@ create trigger qqq after insert on parted_trig_1_1 for each row execute procedur
14651465
insert into parted_trigvalues (50), (1500);
14661466
droptable parted_trig;
14671467

1468+
-- Verify propagation of trigger arguments to partitions
1469+
createtableparted_trig (aint) partition by list (a);
1470+
createtableparted_trig1 partition of parted_trig forvaluesin (1);
1471+
create or replacefunctiontrigger_notice() returns triggeras $$
1472+
declare
1473+
arg1text= TG_ARGV[0];
1474+
arg2integer= TG_ARGV[1];
1475+
begin
1476+
raise notice'trigger % on % % % for % args % %',
1477+
TG_NAME, TG_TABLE_NAME, TG_WHEN, TG_OP, TG_LEVEL, arg1, arg2;
1478+
returnnull;
1479+
end;
1480+
$$ language plpgsql;
1481+
createtriggeraaa after inserton parted_trig
1482+
for each row execute procedure trigger_notice('quirky',1);
1483+
1484+
-- Verify propagation of trigger arguments to partitions attached after creating trigger
1485+
createtableparted_trig2 partition of parted_trig forvaluesin (2);
1486+
createtableparted_trig3 (like parted_trig);
1487+
altertable parted_trig attach partition parted_trig3 forvaluesin (3);
1488+
insert into parted_trigvalues (1), (2), (3);
1489+
droptable parted_trig;
1490+
14681491
-- test irregular partitions (i.e., different column definitions),
14691492
-- including that the WHEN clause works
14701493
createfunctionbark(text) returns bool language plpgsql immutable

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp