Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0f524ea

Browse files
committed
Fix dumping of security_barrier views with circular dependencies.
If a view has circular dependencies, pg_dump splits it into a CREATE TABLE and a CREATE RULE command to break the dependency loop. However, if the view has reloptions, those options cannot be applied in the CREATE TABLE command, because views and tables have different allowed reloptions so CREATE TABLE would reject them. Instead apply the reloptions after the CREATE RULE, using ALTER VIEW SET.
1 parent 4b373e4 commit 0f524ea

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

src/bin/pg_dump/pg_dump.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -5064,6 +5064,16 @@ getRules(Archive *fout, int *numRules)
50645064
}
50655065
else
50665066
ruleinfo[i].separate = true;
5067+
5068+
/*
5069+
* If we're forced to break a dependency loop by dumping a view as a
5070+
* table and separate _RETURN rule, we'll move the view's reloptions
5071+
* to the rule. (This is necessary because tables and views have
5072+
* different valid reloptions, so we can't apply the options until the
5073+
* backend knows it's a view.) Otherwise the rule's reloptions stay
5074+
* NULL.
5075+
*/
5076+
ruleinfo[i].reloptions = NULL;
50675077
}
50685078

50695079
PQclear(res);
@@ -13873,10 +13883,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
1387313883
*/
1387413884
if (rinfo->ev_enabled != 'O')
1387513885
{
13876-
appendPQExpBuffer(cmd, "ALTER TABLE %s.",
13877-
fmtId(tbinfo->dobj.namespace->dobj.name));
13878-
appendPQExpBuffer(cmd, "%s ",
13879-
fmtId(tbinfo->dobj.name));
13886+
appendPQExpBuffer(cmd, "ALTER TABLE %s ", fmtId(tbinfo->dobj.name));
1388013887
switch (rinfo->ev_enabled)
1388113888
{
1388213889
case 'A':
@@ -13894,6 +13901,16 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
1389413901
}
1389513902
}
1389613903

13904+
/*
13905+
* Apply view's reloptions when its ON SELECT rule is separate.
13906+
*/
13907+
if (rinfo->reloptions)
13908+
{
13909+
appendPQExpBuffer(cmd, "ALTER VIEW %s SET (%s);\n",
13910+
fmtId(tbinfo->dobj.name),
13911+
rinfo->reloptions);
13912+
}
13913+
1389713914
/*
1389813915
* DROP must be fully qualified in case same name appears in pg_catalog
1389913916
*/

src/bin/pg_dump/pg_dump.h

+2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ typedef struct _ruleInfo
333333
char ev_enabled;
334334
bool separate; /* TRUE if must dump as separate item */
335335
/* separate is always true for non-ON SELECT rules */
336+
char *reloptions; /* options specified by WITH (...) */
337+
/* reloptions is only set if we need to dump the options with the rule */
336338
} RuleInfo;
337339

338340
typedef struct _triggerInfo

src/bin/pg_dump/pg_dump_sort.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,21 @@ static void
725725
repairViewRuleMultiLoop(DumpableObject *viewobj,
726726
DumpableObject *ruleobj)
727727
{
728+
TableInfo *viewinfo = (TableInfo *) viewobj;
729+
RuleInfo *ruleinfo = (RuleInfo *) ruleobj;
730+
728731
/* remove view's dependency on rule */
729732
removeObjectDependency(viewobj, ruleobj->dumpId);
730733
/* pretend view is a plain table and dump it that way */
731-
((TableInfo *) viewobj)->relkind = 'r'; /* RELKIND_RELATION */
734+
viewinfo->relkind = 'r'; /* RELKIND_RELATION */
732735
/* mark rule as needing its own dump */
733-
((RuleInfo *) ruleobj)->separate = true;
736+
ruleinfo->separate = true;
737+
/* move any reloptions from view to rule */
738+
if (viewinfo->reloptions)
739+
{
740+
ruleinfo->reloptions = viewinfo->reloptions;
741+
viewinfo->reloptions = NULL;
742+
}
734743
/* put back rule's dependency on view */
735744
addObjectDependency(ruleobj, viewobj->dumpId);
736745
/* now that rule is separate, it must be post-data */

0 commit comments

Comments
 (0)