aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_dump_sort.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_dump/pg_dump_sort.c')
-rw-r--r--src/bin/pg_dump/pg_dump_sort.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index e503eaaa26b..523a19c1557 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -869,6 +869,28 @@ repairMatViewBoundaryMultiLoop(DumpableObject *boundaryobj,
}
/*
+ * If a function is involved in a multi-object loop, we can't currently fix
+ * that by splitting it into two DumpableObjects. As a stopgap, we try to fix
+ * it by dropping the constraint that the function be dumped in the pre-data
+ * section. This is sufficient to handle cases where a function depends on
+ * some unique index, as can happen if it has a GROUP BY for example.
+ */
+static void
+repairFunctionBoundaryMultiLoop(DumpableObject *boundaryobj,
+ DumpableObject *nextobj)
+{
+ /* remove boundary's dependency on object after it in loop */
+ removeObjectDependency(boundaryobj, nextobj->dumpId);
+ /* if that object is a function, mark it as postponed into post-data */
+ if (nextobj->objType == DO_FUNC)
+ {
+ FuncInfo *nextinfo = (FuncInfo *) nextobj;
+
+ nextinfo->postponed_def = true;
+ }
+}
+
+/*
* Because we make tables depend on their CHECK constraints, while there
* will be an automatic dependency in the other direction, we need to break
* the loop. If there are no other objects in the loop then we can remove
@@ -1062,6 +1084,28 @@ repairDependencyLoop(DumpableObject **loop,
}
}
+ /* Indirect loop involving function and data boundary */
+ if (nLoop > 2)
+ {
+ for (i = 0; i < nLoop; i++)
+ {
+ if (loop[i]->objType == DO_FUNC)
+ {
+ for (j = 0; j < nLoop; j++)
+ {
+ if (loop[j]->objType == DO_PRE_DATA_BOUNDARY)
+ {
+ DumpableObject *nextobj;
+
+ nextobj = (j < nLoop - 1) ? loop[j + 1] : loop[0];
+ repairFunctionBoundaryMultiLoop(loop[j], nextobj);
+ return;
+ }
+ }
+ }
+ }
+ }
+
/* Table and CHECK constraint */
if (nLoop == 2 &&
loop[0]->objType == DO_TABLE &&