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

Commitaefbc20

Browse files
committed
In pg_dump, ensure that view triggers are processed after view rules.
If a view is split into CREATE TABLE + CREATE RULE to break a circulardependency, then any triggers on the view must be dumped/reloaded afterthe CREATE RULE; else the backend may reject the CREATE TRIGGER becauseit's the wrong type of trigger for a plain table. This works all rightin plain dump/restore because of pg_dump's sorting heuristic that placestriggers after rules. However, when using parallel restore, the orderingmust be enforced by a dependency --- and we didn't have one.Fixing this is a mere matter of adding an addObjectDependency() call,except that we need to be able to find all the triggers belonging to theview relation, and there was no easy way to do that. Add fields topg_dump's TableInfo struct to remember where the associated TriggerInfostruct(s) are.Per bug report from Dennis Kögel. The failure can be exhibited at leastas far back as 9.1, so back-patch to all supported branches.
1 parent014796a commitaefbc20

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5781,6 +5781,9 @@ getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
57815781

57825782
tginfo= (TriggerInfo*)pg_malloc(ntups*sizeof(TriggerInfo));
57835783

5784+
tbinfo->numTriggers=ntups;
5785+
tbinfo->triggers=tginfo;
5786+
57845787
for (j=0;j<ntups;j++)
57855788
{
57865789
tginfo[j].dobj.objType=DO_TRIGGER;

‎src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ typedef struct _tableInfo
287287
intnumParents;/* number of (immediate) parent tables */
288288
struct_tableInfo**parents;/* TableInfos of immediate parents */
289289
struct_tableDataInfo*dataObj;/* TableDataInfo, if dumping its data */
290+
intnumTriggers;/* number of triggers for table */
291+
struct_triggerInfo*triggers;/* array of TriggerInfo structs */
290292
}TableInfo;
291293

292294
typedefstruct_attrDefInfo

‎src/bin/pg_dump/pg_dump_sort.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ repairViewRuleMultiLoop(DumpableObject *viewobj,
878878
{
879879
TableInfo*viewinfo= (TableInfo*)viewobj;
880880
RuleInfo*ruleinfo= (RuleInfo*)ruleobj;
881+
inti;
881882

882883
/* remove view's dependency on rule */
883884
removeObjectDependency(viewobj,ruleobj->dumpId);
@@ -895,6 +896,9 @@ repairViewRuleMultiLoop(DumpableObject *viewobj,
895896
addObjectDependency(ruleobj,viewobj->dumpId);
896897
/* now that rule is separate, it must be post-data */
897898
addObjectDependency(ruleobj,postDataBoundId);
899+
/* also, any triggers on the view must be dumped after the rule */
900+
for (i=0;i<viewinfo->numTriggers;i++)
901+
addObjectDependency(&(viewinfo->triggers[i].dobj),ruleobj->dumpId);
898902
}
899903

900904
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp