18 #include "catalog/pg_class_d.h"
157 "array length mismatch");
219 cmpval = strcmp(obj1->namespace->dobj.
name,
220 obj2->namespace->dobj.
name);
227 else if (obj2->namespace)
231 cmpval = strcmp(obj1->
name, obj2->
name);
251 if (argtype1 && argtype2)
253 if (argtype1->
dobj.namespace && argtype2->
dobj.namespace)
255 cmpval = strcmp(argtype1->
dobj.namespace->dobj.
name,
256 argtype2->
dobj.namespace->dobj.
name);
339 while (!
TopoSort(objs, numObjs, ordering, &nOrdering))
401 *nOrdering = numObjs;
418 idMap = (
int *)
pg_malloc((maxDumpId + 1) *
sizeof(int));
419 for (
i = 0;
i < numObjs;
i++)
423 if (j <= 0 || j > maxDumpId)
429 if (k <= 0 || k > maxDumpId)
430 pg_fatal(
"invalid dependency %d", k);
443 for (
i = numObjs; --
i >= 0;)
474 for (k = 0; k < obj->
nDeps; k++)
490 for (
j = 1;
j <= maxDumpId;
j++)
493 ordering[k++] = objs[idMap[
j]];
558 for (
i = 0;
i < nObjs;
i++)
577 for (
j = 0;
j < looplen;
j++)
578 processed[workspace[
j]->dumpId] =
true;
588 processed[obj->
dumpId] =
true;
594 pg_fatal(
"could not identify dependency loop");
632 if (processed[obj->
dumpId])
639 if (searchFailed[obj->
dumpId] == startPoint)
648 for (
i = 0;
i < depth;
i++)
650 if (workspace[
i] == obj)
657 workspace[depth++] = obj;
691 searchFailed[obj->
dumpId] = startPoint;
799 if (nextinfo->
relkind == RELKIND_MATVIEW)
952 (((
TableInfo *) loop[0])->relkind == RELKIND_VIEW ||
953 ((
TableInfo *) loop[0])->relkind == RELKIND_MATVIEW) &&
954 ((
RuleInfo *) loop[1])->ev_type ==
'1' &&
955 ((
RuleInfo *) loop[1])->is_instead &&
964 (((
TableInfo *) loop[1])->relkind == RELKIND_VIEW ||
965 ((
TableInfo *) loop[1])->relkind == RELKIND_MATVIEW) &&
966 ((
RuleInfo *) loop[0])->ev_type ==
'1' &&
967 ((
RuleInfo *) loop[0])->is_instead &&
977 for (
i = 0;
i < nLoop;
i++)
980 ((
TableInfo *) loop[
i])->relkind == RELKIND_VIEW)
982 for (
j = 0;
j < nLoop;
j++)
985 ((
RuleInfo *) loop[
j])->ev_type ==
'1' &&
1000 for (
i = 0;
i < nLoop;
i++)
1003 ((
TableInfo *) loop[
i])->relkind == RELKIND_MATVIEW)
1005 for (
j = 0;
j < nLoop;
j++)
1011 nextobj = (
j < nLoop - 1) ? loop[
j + 1] : loop[0];
1023 for (
i = 0;
i < nLoop;
i++)
1027 for (
j = 0;
j < nLoop;
j++)
1033 nextobj = (
j < nLoop - 1) ? loop[
j + 1] : loop[0];
1065 for (
i = 0;
i < nLoop;
i++)
1069 for (
j = 0;
j < nLoop;
j++)
1106 if (((
IndxInfo *) loop[0])->parentidx == loop[1]->catId.oid)
1111 else if (((
IndxInfo *) loop[1])->parentidx == loop[0]->catId.oid)
1121 for (
i = 0;
i < nLoop;
i++)
1125 for (
j = 0;
j < nLoop;
j++)
1140 loop[0]->objType ==
DO_TYPE &&
1149 loop[1]->objType ==
DO_TYPE &&
1161 for (
i = 0;
i < nLoop;
i++)
1165 for (
j = 0;
j < nLoop;
j++)
1202 for (
i = 0;
i < nLoop;
i++)
1210 "there are circular foreign-key constraints among these tables:",
1212 for (
i = 0;
i < nLoop;
i++)
1214 pg_log_warning_hint(
"You might not be able to restore the dump without using --disable-triggers or temporarily dropping the constraints.");
1215 pg_log_warning_hint(
"Consider using a full dump instead of a --data-only dump to avoid this problem.");
1227 pg_log_warning(
"could not resolve dependency loop among these items:");
1228 for (
i = 0;
i < nLoop;
i++)
1254 "SCHEMA %s (ID %d OID %u)",
1259 "EXTENSION %s (ID %d OID %u)",
1264 "TYPE %s (ID %d OID %u)",
1269 "SHELL TYPE %s (ID %d OID %u)",
1274 "FUNCTION %s (ID %d OID %u)",
1279 "AGGREGATE %s (ID %d OID %u)",
1284 "OPERATOR %s (ID %d OID %u)",
1289 "ACCESS METHOD %s (ID %d OID %u)",
1294 "OPERATOR CLASS %s (ID %d OID %u)",
1299 "OPERATOR FAMILY %s (ID %d OID %u)",
1304 "COLLATION %s (ID %d OID %u)",
1309 "CONVERSION %s (ID %d OID %u)",
1314 "TABLE %s (ID %d OID %u)",
1319 "TABLE ATTACH %s (ID %d)",
1324 "ATTRDEF %s.%s (ID %d OID %u)",
1327 obj->dumpId, obj->catId.oid);
1331 "INDEX %s (ID %d OID %u)",
1332 obj->name, obj->dumpId, obj->catId.oid);
1336 "INDEX ATTACH %s (ID %d)",
1337 obj->name, obj->dumpId);
1341 "STATISTICS %s (ID %d OID %u)",
1342 obj->name, obj->dumpId, obj->catId.oid);
1346 "REFRESH MATERIALIZED VIEW %s (ID %d OID %u)",
1347 obj->name, obj->dumpId, obj->catId.oid);
1351 "RULE %s (ID %d OID %u)",
1352 obj->name, obj->dumpId, obj->catId.oid);
1356 "TRIGGER %s (ID %d OID %u)",
1357 obj->name, obj->dumpId, obj->catId.oid);
1361 "EVENT TRIGGER %s (ID %d OID %u)",
1362 obj->name, obj->dumpId, obj->catId.oid);
1366 "CONSTRAINT %s (ID %d OID %u)",
1367 obj->name, obj->dumpId, obj->catId.oid);
1371 "FK CONSTRAINT %s (ID %d OID %u)",
1372 obj->name, obj->dumpId, obj->catId.oid);
1376 "PROCEDURAL LANGUAGE %s (ID %d OID %u)",
1377 obj->name, obj->dumpId, obj->catId.oid);
1381 "CAST %u to %u (ID %d OID %u)",
1384 obj->dumpId, obj->catId.oid);
1388 "TRANSFORM %u lang %u (ID %d OID %u)",
1391 obj->dumpId, obj->catId.oid);
1395 "TABLE DATA %s (ID %d OID %u)",
1396 obj->name, obj->dumpId, obj->catId.oid);
1400 "SEQUENCE SET %s (ID %d OID %u)",
1401 obj->name, obj->dumpId, obj->catId.oid);
1405 "DUMMY TYPE %s (ID %d OID %u)",
1406 obj->name, obj->dumpId, obj->catId.oid);
1410 "TEXT SEARCH PARSER %s (ID %d OID %u)",
1411 obj->name, obj->dumpId, obj->catId.oid);
1415 "TEXT SEARCH DICTIONARY %s (ID %d OID %u)",
1416 obj->name, obj->dumpId, obj->catId.oid);
1420 "TEXT SEARCH TEMPLATE %s (ID %d OID %u)",
1421 obj->name, obj->dumpId, obj->catId.oid);
1425 "TEXT SEARCH CONFIGURATION %s (ID %d OID %u)",
1426 obj->name, obj->dumpId, obj->catId.oid);
1430 "FOREIGN DATA WRAPPER %s (ID %d OID %u)",
1431 obj->name, obj->dumpId, obj->catId.oid);
1435 "FOREIGN SERVER %s (ID %d OID %u)",
1436 obj->name, obj->dumpId, obj->catId.oid);
1440 "DEFAULT ACL %s (ID %d OID %u)",
1441 obj->name, obj->dumpId, obj->catId.oid);
1445 "LARGE OBJECT (ID %d OID %u)",
1446 obj->dumpId, obj->catId.oid);
1450 "LARGE OBJECT DATA (ID %d)",
1455 "POLICY (ID %d OID %u)",
1456 obj->dumpId, obj->catId.oid);
1460 "PUBLICATION (ID %d OID %u)",
1461 obj->dumpId, obj->catId.oid);
1465 "PUBLICATION TABLE (ID %d OID %u)",
1466 obj->dumpId, obj->catId.oid);
1470 "PUBLICATION TABLES IN SCHEMA (ID %d OID %u)",
1471 obj->dumpId, obj->catId.oid);
1475 "SUBSCRIPTION (ID %d OID %u)",
1476 obj->dumpId, obj->catId.oid);
1480 "SUBSCRIPTION TABLE (ID %d OID %u)",
1481 obj->dumpId, obj->catId.oid);
1485 "PRE-DATA BOUNDARY (ID %d)",
1490 "POST-DATA BOUNDARY (ID %d)",
1496 "object type %d (ID %d OID %u)",
1505 int ai = (int) (intptr_t)
a;
1506 int bi = (int) (intptr_t)
b;
void addObjectDependency(DumpableObject *dobj, DumpId refId)
DumpableObject * findObjectByDumpId(DumpId dumpId)
DumpId getMaxDumpId(void)
TypeInfo * findTypeByOid(Oid oid)
void removeObjectDependency(DumpableObject *dobj, DumpId refId)
void binaryheap_build(binaryheap *heap)
void binaryheap_add(binaryheap *heap, bh_node_type d)
bh_node_type binaryheap_remove_first(binaryheap *heap)
binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)
void binaryheap_free(binaryheap *heap)
void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)
#define binaryheap_empty(h)
#define ngettext(s, p, n)
static void PGresult const char * p2
static int * beforeConstraints
void * pg_malloc0(size_t size)
void * pg_malloc(size_t size)
static int pg_cmp_s32(int32 a, int32 b)
#define pg_log_warning_hint(...)
#define pg_log_warning_detail(...)
#define DUMP_COMPONENT_DEFINITION
@ DO_PUBLICATION_TABLE_IN_SCHEMA
StaticAssertDecl(lengthof(dbObjectTypePriority)==(DO_SUBSCRIPTION_REL+1), "array length mismatch")
static void repairMatViewBoundaryMultiLoop(DumpableObject *boundaryobj, DumpableObject *nextobj)
static void repairTableAttrDefLoop(DumpableObject *tableobj, DumpableObject *attrdefobj)
static int findLoop(DumpableObject *obj, DumpId startPoint, bool *processed, DumpId *searchFailed, DumpableObject **workspace, int depth)
static void findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs)
static void repairTableConstraintLoop(DumpableObject *tableobj, DumpableObject *constraintobj)
static void repairTableAttrDefMultiLoop(DumpableObject *tableobj, DumpableObject *attrdefobj)
static const int dbObjectTypePriority[]
@ PRIO_POST_DATA_BOUNDARY
@ PRIO_PUBLICATION_TABLE_IN_SCHEMA
static int DOTypeNameCompare(const void *p1, const void *p2)
static void repairViewRuleMultiLoop(DumpableObject *viewobj, DumpableObject *ruleobj)
static void repairDomainConstraintLoop(DumpableObject *domainobj, DumpableObject *constraintobj)
static void repairTableConstraintMultiLoop(DumpableObject *tableobj, DumpableObject *constraintobj)
void sortDumpableObjects(DumpableObject **objs, int numObjs, DumpId preBoundaryId, DumpId postBoundaryId)
static DumpId preDataBoundId
static void describeDumpableObject(DumpableObject *obj, char *buf, int bufsize)
static void repairTypeFuncLoop(DumpableObject *typeobj, DumpableObject *funcobj)
static void repairDomainConstraintMultiLoop(DumpableObject *domainobj, DumpableObject *constraintobj)
static int int_cmp(void *a, void *b, void *arg)
static void repairIndexLoop(DumpableObject *partedindex, DumpableObject *partindex)
void sortDumpableObjectsByTypeName(DumpableObject **objs, int numObjs)
static void repairViewRuleLoop(DumpableObject *viewobj, DumpableObject *ruleobj)
static void repairFunctionBoundaryMultiLoop(DumpableObject *boundaryobj, DumpableObject *nextobj)
static void repairDependencyLoop(DumpableObject **loop, int nLoop)
static bool TopoSort(DumpableObject **objs, int numObjs, DumpableObject **ordering, int *nOrdering)
static DumpId postDataBoundId
#define pg_log_warning(...)
#define qsort(a, b, c, d)
DumpableObjectType objType
struct _shellTypeInfo * shellType