PostgreSQL Source Code  git master
common.c File Reference
#include "postgres_fe.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
#include "pg_dump.h"
#include <ctype.h>
#include "catalog/pg_class_d.h"
#include "fe_utils/string_utils.h"
Include dependency graph for common.c:

Go to the source code of this file.

Functions

static void flagInhTables (Archive *fout, TableInfo *tbinfo, int numTables, InhInfo *inhinfo, int numInherits)
 
static void flagInhIndexes (Archive *fout, TableInfo *tblinfo, int numTables)
 
static void flagInhAttrs (DumpOptions *dopt, TableInfo *tblinfo, int numTables)
 
static DumpableObject ** buildIndexArray (void *objArray, int numObjs, Size objSize)
 
static int DOCatalogIdCompare (const void *p1, const void *p2)
 
static int ExtensionMemberIdCompare (const void *p1, const void *p2)
 
static void findParentsByOid (TableInfo *self, InhInfo *inhinfo, int numInherits)
 
static int strInArray (const char *pattern, char **arr, int arr_size)
 
static IndxInfofindIndexByOid (Oid oid, DumpableObject **idxinfoindex, int numIndexes)
 
TableInfogetSchemaData (Archive *fout, int *numTablesPtr)
 
static void flagInhIndexes (Archive *fout, TableInfo tblinfo[], int numTables)
 
void AssignDumpId (DumpableObject *dobj)
 
DumpId createDumpId (void)
 
DumpId getMaxDumpId (void)
 
DumpableObjectfindObjectByDumpId (DumpId dumpId)
 
DumpableObjectfindObjectByCatalogId (CatalogId catalogId)
 
static DumpableObjectfindObjectByOid (Oid oid, DumpableObject **indexArray, int numObjs)
 
void getDumpableObjects (DumpableObject ***objs, int *numObjs)
 
void addObjectDependency (DumpableObject *dobj, DumpId refId)
 
void removeObjectDependency (DumpableObject *dobj, DumpId refId)
 
TableInfofindTableByOid (Oid oid)
 
TypeInfofindTypeByOid (Oid oid)
 
FuncInfofindFuncByOid (Oid oid)
 
OprInfofindOprByOid (Oid oid)
 
CollInfofindCollationByOid (Oid oid)
 
NamespaceInfofindNamespaceByOid (Oid oid)
 
ExtensionInfofindExtensionByOid (Oid oid)
 
void setExtensionMembership (ExtensionMemberId *extmems, int nextmems)
 
ExtensionInfofindOwningExtension (CatalogId catalogId)
 
void parseOidArray (const char *str, Oid *array, int arraysize)
 

Variables

static DumpableObject ** dumpIdMap = NULL
 
static int allocedDumpIds = 0
 
static DumpId lastDumpId = 0
 
static bool catalogIdMapValid = false
 
static DumpableObject ** catalogIdMap = NULL
 
static int numCatalogIds = 0
 
static DumpableObject ** tblinfoindex
 
static DumpableObject ** typinfoindex
 
static DumpableObject ** funinfoindex
 
static DumpableObject ** oprinfoindex
 
static DumpableObject ** collinfoindex
 
static DumpableObject ** nspinfoindex
 
static DumpableObject ** extinfoindex
 
static int numTables
 
static int numTypes
 
static int numFuncs
 
static int numOperators
 
static int numCollations
 
static int numNamespaces
 
static int numExtensions
 
static ExtensionMemberIdextmembers
 
static int numextmembers
 

Function Documentation

◆ addObjectDependency()

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 805 of file common.c.

References _dumpableObject::allocDeps, _dumpableObject::dependencies, _dumpableObject::nDeps, pg_malloc(), and pg_realloc().

Referenced by addBoundaryDependencies(), buildMatViewRefreshDependencies(), checkExtensionMembership(), flagInhAttrs(), flagInhIndexes(), getDependencies(), getDomainConstraints(), getRules(), getTableAttrs(), getTableDataFKConstraints(), makeTableDataInfo(), processExtensionTables(), repairDomainConstraintMultiLoop(), repairTableAttrDefMultiLoop(), repairTableConstraintMultiLoop(), repairTypeFuncLoop(), and repairViewRuleMultiLoop().

806 {
807  if (dobj->nDeps >= dobj->allocDeps)
808  {
809  if (dobj->allocDeps <= 0)
810  {
811  dobj->allocDeps = 16;
812  dobj->dependencies = (DumpId *)
813  pg_malloc(dobj->allocDeps * sizeof(DumpId));
814  }
815  else
816  {
817  dobj->allocDeps *= 2;
818  dobj->dependencies = (DumpId *)
819  pg_realloc(dobj->dependencies,
820  dobj->allocDeps * sizeof(DumpId));
821  }
822  }
823  dobj->dependencies[dobj->nDeps++] = refId;
824 }
int DumpId
Definition: pg_backup.h:235
DumpId * dependencies
Definition: pg_dump.h:139
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65

◆ AssignDumpId()

void AssignDumpId ( DumpableObject dobj)

Definition at line 569 of file common.c.

References _dumpableObject::allocDeps, allocedDumpIds, catalogIdMapValid, _dumpableObject::dependencies, _dumpableObject::dump, DUMP_COMPONENT_ALL, _dumpableObject::dumpId, _dumpableObject::ext_member, lastDumpId, _dumpableObject::name, _dumpableObject::nDeps, pg_malloc(), and pg_realloc().

Referenced by createBoundaryObjects(), flagInhAttrs(), flagInhIndexes(), getAccessMethods(), getAggregates(), getBlobs(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getDomainConstraints(), getEventTriggers(), getExtendedStatistics(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getPolicies(), getProcLangs(), getPublications(), getPublicationTables(), getRules(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), and makeTableDataInfo().

570 {
571  dobj->dumpId = ++lastDumpId;
572  dobj->name = NULL; /* must be set later */
573  dobj->namespace = NULL; /* may be set later */
574  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
575  dobj->ext_member = false; /* default assumption */
576  dobj->dependencies = NULL;
577  dobj->nDeps = 0;
578  dobj->allocDeps = 0;
579 
580  while (dobj->dumpId >= allocedDumpIds)
581  {
582  int newAlloc;
583 
584  if (allocedDumpIds <= 0)
585  {
586  newAlloc = 256;
588  pg_malloc(newAlloc * sizeof(DumpableObject *));
589  }
590  else
591  {
592  newAlloc = allocedDumpIds * 2;
594  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
595  }
596  memset(dumpIdMap + allocedDumpIds, 0,
597  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
598  allocedDumpIds = newAlloc;
599  }
600  dumpIdMap[dobj->dumpId] = dobj;
601 
602  /* mark catalogIdMap invalid, but don't rebuild it yet */
603  catalogIdMapValid = false;
604 }
char * name
Definition: pg_dump.h:134
static int allocedDumpIds
Definition: common.c:32
DumpComponents dump
Definition: pg_dump.h:135
static DumpId lastDumpId
Definition: common.c:33
static DumpableObject ** dumpIdMap
Definition: common.c:31
DumpId * dependencies
Definition: pg_dump.h:139
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:133
bool ext_member
Definition: pg_dump.h:138
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
static bool catalogIdMapValid
Definition: common.c:38
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:100

◆ buildIndexArray()

static DumpableObject ** buildIndexArray ( void *  objArray,
int  numObjs,
Size  objSize 
)
static

Definition at line 740 of file common.c.

References DOCatalogIdCompare(), i, pg_malloc(), and qsort.

Referenced by flagInhIndexes(), and getSchemaData().

741 {
742  DumpableObject **ptrs;
743  int i;
744 
745  ptrs = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
746  for (i = 0; i < numObjs; i++)
747  ptrs[i] = (DumpableObject *) ((char *) objArray + i * objSize);
748 
749  /* We can use DOCatalogIdCompare to sort since its first key is OID */
750  if (numObjs > 1)
751  qsort((void *) ptrs, numObjs, sizeof(DumpableObject *),
753 
754  return ptrs;
755 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:761
int i
#define qsort(a, b, c, d)
Definition: port.h:421

◆ createDumpId()

◆ DOCatalogIdCompare()

static int DOCatalogIdCompare ( const void *  p1,
const void *  p2 
)
static

Definition at line 761 of file common.c.

References _dumpableObject::catId, CatalogId::oid, oidcmp, and CatalogId::tableoid.

Referenced by buildIndexArray(), and findObjectByCatalogId().

762 {
763  const DumpableObject *obj1 = *(DumpableObject *const *) p1;
764  const DumpableObject *obj2 = *(DumpableObject *const *) p2;
765  int cmpval;
766 
767  /*
768  * Compare OID first since it's usually unique, whereas there will only be
769  * a few distinct values of tableoid.
770  */
771  cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
772  if (cmpval == 0)
773  cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
774  return cmpval;
775 }
Oid tableoid
Definition: pg_backup.h:231
#define oidcmp(x, y)
Definition: pg_dump.h:20
CatalogId catId
Definition: pg_dump.h:132

◆ ExtensionMemberIdCompare()

static int ExtensionMemberIdCompare ( const void *  p1,
const void *  p2 
)
static

Definition at line 995 of file common.c.

References _extensionMemberId::catId, CatalogId::oid, oidcmp, and CatalogId::tableoid.

Referenced by setExtensionMembership().

996 {
997  const ExtensionMemberId *obj1 = (const ExtensionMemberId *) p1;
998  const ExtensionMemberId *obj2 = (const ExtensionMemberId *) p2;
999  int cmpval;
1000 
1001  /*
1002  * Compare OID first since it's usually unique, whereas there will only be
1003  * a few distinct values of tableoid.
1004  */
1005  cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
1006  if (cmpval == 0)
1007  cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
1008  return cmpval;
1009 }
Oid tableoid
Definition: pg_backup.h:231
#define oidcmp(x, y)
Definition: pg_dump.h:20
CatalogId catId
Definition: pg_dump.h:634

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 896 of file common.c.

References findObjectByOid(), and numCollations.

Referenced by createDummyViewAsClause(), dumpCompositeType(), dumpDomain(), dumpRangeType(), and dumpTableSchema().

897 {
899 }
static DumpableObject ** collinfoindex
Definition: common.c:54
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numCollations
Definition: common.c:61

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 918 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

919 {
921 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numExtensions
Definition: common.c:63
static DumpableObject ** extinfoindex
Definition: common.c:56

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 874 of file common.c.

References findObjectByOid(), and numFuncs.

Referenced by dumpCast(), dumpProcLang(), and dumpTransform().

875 {
876  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
877 }
static int numFuncs
Definition: common.c:59
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static DumpableObject ** funinfoindex
Definition: common.c:52

◆ findIndexByOid()

static IndxInfo * findIndexByOid ( Oid  oid,
DumpableObject **  idxinfoindex,
int  numIndexes 
)
static

Definition at line 931 of file common.c.

References findObjectByOid().

Referenced by flagInhIndexes().

932 {
933  return (IndxInfo *) findObjectByOid(oid, idxinfoindex, numIndexes);
934 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 907 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

908 {
910 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numNamespaces
Definition: common.c:62
static DumpableObject ** nspinfoindex
Definition: common.c:55

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 651 of file common.c.

References catalogIdMap, catalogIdMapValid, difference(), DOCatalogIdCompare(), free, getDumpableObjects(), numCatalogIds, CatalogId::oid, oidcmp, qsort, and CatalogId::tableoid.

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

652 {
653  DumpableObject **low;
654  DumpableObject **high;
655 
656  if (!catalogIdMapValid)
657  {
658  if (catalogIdMap)
661  if (numCatalogIds > 1)
662  qsort((void *) catalogIdMap, numCatalogIds,
664  catalogIdMapValid = true;
665  }
666 
667  /*
668  * We could use bsearch() here, but the notational cruft of calling
669  * bsearch is nearly as bad as doing it ourselves; and the generalized
670  * bsearch function is noticeably slower as well.
671  */
672  if (numCatalogIds <= 0)
673  return NULL;
674  low = catalogIdMap;
675  high = catalogIdMap + (numCatalogIds - 1);
676  while (low <= high)
677  {
678  DumpableObject **middle;
679  int difference;
680 
681  middle = low + (high - low) / 2;
682  /* comparison must match DOCatalogIdCompare, below */
683  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
684  if (difference == 0)
685  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
686  if (difference == 0)
687  return *middle;
688  else if (difference < 0)
689  low = middle + 1;
690  else
691  high = middle - 1;
692  }
693  return NULL;
694 }
Oid tableoid
Definition: pg_backup.h:231
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:761
static int numCatalogIds
Definition: common.c:40
Datum difference(PG_FUNCTION_ARGS)
#define free(a)
Definition: header.h:65
static DumpableObject ** catalogIdMap
Definition: common.c:39
static bool catalogIdMapValid
Definition: common.c:38
#define qsort(a, b, c, d)
Definition: port.h:421
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:783

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 633 of file common.c.

References allocedDumpIds.

Referenced by binary_upgrade_extension_member(), BuildArchiveDependencies(), dumpConstraint(), dumpExtension(), findDumpableDependencies(), and findLoop().

634 {
635  if (dumpId <= 0 || dumpId >= allocedDumpIds)
636  return NULL; /* out of range? */
637  return dumpIdMap[dumpId];
638 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31

◆ findObjectByOid()

static DumpableObject* findObjectByOid ( Oid  oid,
DumpableObject **  indexArray,
int  numObjs 
)
static

Definition at line 702 of file common.c.

References difference(), and oidcmp.

Referenced by findCollationByOid(), findExtensionByOid(), findFuncByOid(), findIndexByOid(), findNamespaceByOid(), findOprByOid(), findTableByOid(), and findTypeByOid().

703 {
704  DumpableObject **low;
705  DumpableObject **high;
706 
707  /*
708  * This is the same as findObjectByCatalogId except we assume we need not
709  * look at table OID because the objects are all the same type.
710  *
711  * We could use bsearch() here, but the notational cruft of calling
712  * bsearch is nearly as bad as doing it ourselves; and the generalized
713  * bsearch function is noticeably slower as well.
714  */
715  if (numObjs <= 0)
716  return NULL;
717  low = indexArray;
718  high = indexArray + (numObjs - 1);
719  while (low <= high)
720  {
721  DumpableObject **middle;
722  int difference;
723 
724  middle = low + (high - low) / 2;
725  difference = oidcmp((*middle)->catId.oid, oid);
726  if (difference == 0)
727  return *middle;
728  else if (difference < 0)
729  low = middle + 1;
730  else
731  high = middle - 1;
732  }
733  return NULL;
734 }
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 885 of file common.c.

References findObjectByOid(), and numOperators.

Referenced by getFormattedOperatorName().

886 {
888 }
static DumpableObject ** oprinfoindex
Definition: common.c:53
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static int numOperators
Definition: common.c:60

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 957 of file common.c.

References _extensionMemberId::catId, difference(), _extensionMemberId::ext, extmembers, numextmembers, CatalogId::oid, oidcmp, and CatalogId::tableoid.

Referenced by checkExtensionMembership().

958 {
959  ExtensionMemberId *low;
960  ExtensionMemberId *high;
961 
962  /*
963  * We could use bsearch() here, but the notational cruft of calling
964  * bsearch is nearly as bad as doing it ourselves; and the generalized
965  * bsearch function is noticeably slower as well.
966  */
967  if (numextmembers <= 0)
968  return NULL;
969  low = extmembers;
970  high = extmembers + (numextmembers - 1);
971  while (low <= high)
972  {
973  ExtensionMemberId *middle;
974  int difference;
975 
976  middle = low + (high - low) / 2;
977  /* comparison must match ExtensionMemberIdCompare, below */
978  difference = oidcmp(middle->catId.oid, catalogId.oid);
979  if (difference == 0)
980  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
981  if (difference == 0)
982  return middle->ext;
983  else if (difference < 0)
984  low = middle + 1;
985  else
986  high = middle - 1;
987  }
988  return NULL;
989 }
ExtensionInfo * ext
Definition: pg_dump.h:635
Oid tableoid
Definition: pg_backup.h:231
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
static ExtensionMemberId * extmembers
Definition: common.c:66
static int numextmembers
Definition: common.c:67
CatalogId catId
Definition: pg_dump.h:634

◆ findParentsByOid()

static void findParentsByOid ( TableInfo self,
InhInfo inhinfo,
int  numInherits 
)
static

Definition at line 1017 of file common.c.

References exit_nicely, findTableByOid(), i, _tableInfo::parents, pg_malloc(), and write_msg().

Referenced by flagInhTables().

1019 {
1020  Oid oid = self->dobj.catId.oid;
1021  int i,
1022  j;
1023  int numParents;
1024 
1025  numParents = 0;
1026  for (i = 0; i < numInherits; i++)
1027  {
1028  if (inhinfo[i].inhrelid == oid)
1029  numParents++;
1030  }
1031 
1032  self->numParents = numParents;
1033 
1034  if (numParents > 0)
1035  {
1036  self->parents = (TableInfo **)
1037  pg_malloc(sizeof(TableInfo *) * numParents);
1038  j = 0;
1039  for (i = 0; i < numInherits; i++)
1040  {
1041  if (inhinfo[i].inhrelid == oid)
1042  {
1043  TableInfo *parent;
1044 
1045  parent = findTableByOid(inhinfo[i].inhparent);
1046  if (parent == NULL)
1047  {
1048  write_msg(NULL, "failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n",
1049  inhinfo[i].inhparent,
1050  self->dobj.name,
1051  oid);
1052  exit_nicely(1);
1053  }
1054  self->parents[j++] = parent;
1055  }
1056  }
1057  }
1058  else
1059  self->parents = NULL;
1060 }
char * name
Definition: pg_dump.h:134
TableInfo * findTableByOid(Oid oid)
Definition: common.c:852
struct _tableInfo ** parents
Definition: pg_dump.h:332
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
unsigned int Oid
Definition: postgres_ext.h:31
DumpableObject dobj
Definition: pg_dump.h:262
#define exit_nicely(code)
Definition: pg_dumpall.c:89
void write_msg(const char *modulename, const char *fmt,...)
int i

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 852 of file common.c.

References findObjectByOid(), and numTables.

Referenced by dumpSequence(), findParentsByOid(), getOwnedSeqs(), getRules(), getTableDataFKConstraints(), processExtensionTables(), and selectDumpableType().

853 {
855 }
static int numTables
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static DumpableObject ** tblinfoindex
Definition: common.c:50

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 863 of file common.c.

References findObjectByOid(), and numTypes.

Referenced by DOTypeNameCompare(), getCasts(), and getTransforms().

864 {
865  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
866 }
static int numTypes
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:702
static DumpableObject ** typinfoindex
Definition: common.c:51

◆ flagInhAttrs()

static void flagInhAttrs ( DumpOptions dopt,
TableInfo tblinfo,
int  numTables 
)
static

Definition at line 463 of file common.c.

References addObjectDependency(), _attrDefInfo::adef_expr, _attrDefInfo::adnum, _attrDefInfo::adtable, AssignDumpId(), _tableInfo::attisdropped, _tableInfo::attnames, _tableInfo::attrdefs, _dumpableObject::catId, DO_ATTRDEF, _tableInfo::dobj, _attrDefInfo::dobj, _dumpableObject::dump, _dumpableObject::dumpId, i, _tableInfo::inhNotNull, _dumpableObject::name, _tableInfo::notnull, _tableInfo::numatts, _tableInfo::numParents, numTables, _dumpableObject::objType, CatalogId::oid, _tableInfo::parents, pg_malloc(), pg_strdup(), _tableInfo::relkind, _attrDefInfo::separate, shouldPrintColumn(), strInArray(), and CatalogId::tableoid.

Referenced by getSchemaData().

464 {
465  int i,
466  j,
467  k;
468 
469  for (i = 0; i < numTables; i++)
470  {
471  TableInfo *tbinfo = &(tblinfo[i]);
472  int numParents;
473  TableInfo **parents;
474 
475  /* Some kinds never have parents */
476  if (tbinfo->relkind == RELKIND_SEQUENCE ||
477  tbinfo->relkind == RELKIND_VIEW ||
478  tbinfo->relkind == RELKIND_MATVIEW)
479  continue;
480 
481  /* Don't bother computing anything for non-target tables, either */
482  if (!tbinfo->dobj.dump)
483  continue;
484 
485  numParents = tbinfo->numParents;
486  parents = tbinfo->parents;
487 
488  if (numParents == 0)
489  continue; /* nothing to see here, move along */
490 
491  /* For each column, search for matching column names in parent(s) */
492  for (j = 0; j < tbinfo->numatts; j++)
493  {
494  bool foundNotNull; /* Attr was NOT NULL in a parent */
495  bool foundDefault; /* Found a default in a parent */
496 
497  /* no point in examining dropped columns */
498  if (tbinfo->attisdropped[j])
499  continue;
500 
501  foundNotNull = false;
502  foundDefault = false;
503  for (k = 0; k < numParents; k++)
504  {
505  TableInfo *parent = parents[k];
506  int inhAttrInd;
507 
508  inhAttrInd = strInArray(tbinfo->attnames[j],
509  parent->attnames,
510  parent->numatts);
511  if (inhAttrInd >= 0)
512  {
513  foundNotNull |= parent->notnull[inhAttrInd];
514  foundDefault |= (parent->attrdefs[inhAttrInd] != NULL);
515  }
516  }
517 
518  /* Remember if we found inherited NOT NULL */
519  tbinfo->inhNotNull[j] = foundNotNull;
520 
521  /* Manufacture a DEFAULT NULL clause if necessary */
522  if (foundDefault && tbinfo->attrdefs[j] == NULL)
523  {
524  AttrDefInfo *attrDef;
525 
526  attrDef = (AttrDefInfo *) pg_malloc(sizeof(AttrDefInfo));
527  attrDef->dobj.objType = DO_ATTRDEF;
528  attrDef->dobj.catId.tableoid = 0;
529  attrDef->dobj.catId.oid = 0;
530  AssignDumpId(&attrDef->dobj);
531  attrDef->dobj.name = pg_strdup(tbinfo->dobj.name);
532  attrDef->dobj.namespace = tbinfo->dobj.namespace;
533  attrDef->dobj.dump = tbinfo->dobj.dump;
534 
535  attrDef->adtable = tbinfo;
536  attrDef->adnum = j + 1;
537  attrDef->adef_expr = pg_strdup("NULL");
538 
539  /* Will column be dumped explicitly? */
540  if (shouldPrintColumn(dopt, tbinfo, j))
541  {
542  attrDef->separate = false;
543  /* No dependency needed: NULL cannot have dependencies */
544  }
545  else
546  {
547  /* column will be suppressed, print default separately */
548  attrDef->separate = true;
549  /* ensure it comes out after the table */
550  addObjectDependency(&attrDef->dobj,
551  tbinfo->dobj.dumpId);
552  }
553 
554  tbinfo->attrdefs[j] = attrDef;
555  }
556  }
557  }
558 }
char * name
Definition: pg_dump.h:134
struct _tableInfo ** parents
Definition: pg_dump.h:332
char relkind
Definition: pg_dump.h:268
DumpComponents dump
Definition: pg_dump.h:135
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno)
Definition: pg_dump.c:8585
bool * inhNotNull
Definition: pg_dump.h:321
DumpId dumpId
Definition: pg_dump.h:133
static int numTables
Definition: common.c:57
char ** attnames
Definition: pg_dump.h:305
DumpableObject dobj
Definition: pg_dump.h:262
static int strInArray(const char *pattern, char **arr, int arr_size)
Definition: common.c:1125
bool separate
Definition: pg_dump.h:346
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
bool * attisdropped
Definition: pg_dump.h:311
TableInfo * adtable
Definition: pg_dump.h:343
int numatts
Definition: pg_dump.h:304
bool * notnull
Definition: pg_dump.h:320
DumpableObject dobj
Definition: pg_dump.h:342
struct _attrDefInfo ** attrdefs
Definition: pg_dump.h:322
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:805
CatalogId catId
Definition: pg_dump.h:132
int i
int numParents
Definition: pg_dump.h:331
DumpableObjectType objType
Definition: pg_dump.h:131
char * adef_expr
Definition: pg_dump.h:345

◆ flagInhIndexes() [1/2]

static void flagInhIndexes ( Archive fout,
TableInfo tblinfo,
int  numTables 
)
static

Referenced by getSchemaData().

◆ flagInhIndexes() [2/2]

static void flagInhIndexes ( Archive fout,
TableInfo  tblinfo[],
int  numTables 
)
static

Definition at line 373 of file common.c.

References addObjectDependency(), Assert, AssignDumpId(), buildIndexArray(), _dumpableObject::catId, DO_INDEX_ATTACH, _tableInfo::dobj, _indxInfo::dobj, _indexAttachInfo::dobj, _dumpableObject::dumpId, findIndexByOid(), getMaxDumpId(), i, _tableInfo::indexes, _dumpableObject::name, _tableInfo::numIndexes, numTables, _dumpableObject::objType, CatalogId::oid, _indxInfo::parentidx, _indexAttachInfo::parentIdx, _tableInfo::parents, _indexAttachInfo::partitionIdx, pg_free(), pg_malloc0(), pg_strdup(), and CatalogId::tableoid.

374 {
375  int i,
376  j,
377  k;
378  DumpableObject ***parentIndexArray;
379 
380  parentIndexArray = (DumpableObject ***)
381  pg_malloc0(getMaxDumpId() * sizeof(DumpableObject **));
382 
383  for (i = 0; i < numTables; i++)
384  {
385  TableInfo *parenttbl;
386  IndexAttachInfo *attachinfo;
387 
388  if (!tblinfo[i].ispartition || tblinfo[i].numParents == 0)
389  continue;
390 
391  Assert(tblinfo[i].numParents == 1);
392  parenttbl = tblinfo[i].parents[0];
393 
394  /*
395  * We need access to each parent table's index list, but there is no
396  * index to cover them outside of this function. To avoid having to
397  * sort every parent table's indexes each time we come across each of
398  * its partitions, create an indexed array for each parent the first
399  * time it is required.
400  */
401  if (parentIndexArray[parenttbl->dobj.dumpId] == NULL)
402  parentIndexArray[parenttbl->dobj.dumpId] =
403  buildIndexArray(parenttbl->indexes,
404  parenttbl->numIndexes,
405  sizeof(IndxInfo));
406 
407  attachinfo = (IndexAttachInfo *)
408  pg_malloc0(tblinfo[i].numIndexes * sizeof(IndexAttachInfo));
409  for (j = 0, k = 0; j < tblinfo[i].numIndexes; j++)
410  {
411  IndxInfo *index = &(tblinfo[i].indexes[j]);
412  IndxInfo *parentidx;
413 
414  if (index->parentidx == 0)
415  continue;
416 
417  parentidx = findIndexByOid(index->parentidx,
418  parentIndexArray[parenttbl->dobj.dumpId],
419  parenttbl->numIndexes);
420  if (parentidx == NULL)
421  continue;
422 
423  attachinfo[k].dobj.objType = DO_INDEX_ATTACH;
424  attachinfo[k].dobj.catId.tableoid = 0;
425  attachinfo[k].dobj.catId.oid = 0;
426  AssignDumpId(&attachinfo[k].dobj);
427  attachinfo[k].dobj.name = pg_strdup(index->dobj.name);
428  attachinfo[k].parentIdx = parentidx;
429  attachinfo[k].partitionIdx = index;
430 
431  /*
432  * We want dependencies from parent to partition (so that the
433  * partition index is created first), and another one from attach
434  * object to parent (so that the partition index is attached once
435  * the parent index has been created).
436  */
437  addObjectDependency(&parentidx->dobj, index->dobj.dumpId);
438  addObjectDependency(&attachinfo[k].dobj, parentidx->dobj.dumpId);
439 
440  k++;
441  }
442  }
443 
444  for (i = 0; i < numTables; i++)
445  if (parentIndexArray[i])
446  pg_free(parentIndexArray[i]);
447  pg_free(parentIndexArray);
448 }
char * name
Definition: pg_dump.h:134
struct _tableInfo ** parents
Definition: pg_dump.h:332
Oid tableoid
Definition: pg_backup.h:231
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:569
DumpId dumpId
Definition: pg_dump.h:133
static int numTables
Definition: common.c:57
DumpableObject dobj
Definition: pg_dump.h:262
Oid parentidx
Definition: pg_dump.h:370
static DumpableObject ** buildIndexArray(void *objArray, int numObjs, Size objSize)
Definition: common.c:740
Definition: type.h:89
DumpableObject dobj
Definition: pg_dump.h:378
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
IndxInfo * partitionIdx
Definition: pg_dump.h:380
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static IndxInfo * findIndexByOid(Oid oid, DumpableObject **idxinfoindex, int numIndexes)
Definition: common.c:931
int numIndexes
Definition: pg_dump.h:333
DumpId getMaxDumpId(void)
Definition: common.c:622
#define Assert(condition)
Definition: c.h:699
IndxInfo * parentIdx
Definition: pg_dump.h:379
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:805
CatalogId catId
Definition: pg_dump.h:132
struct _indxInfo * indexes
Definition: pg_dump.h:334
DumpableObject dobj
Definition: pg_dump.h:359
int i
DumpableObjectType objType
Definition: pg_dump.h:131

◆ flagInhTables()

static void flagInhTables ( Archive fout,
TableInfo tbinfo,
int  numTables,
InhInfo inhinfo,
int  numInherits 
)
static

Definition at line 314 of file common.c.

References Archive::dopt, findParentsByOid(), i, _tableInfo::ispartition, _dumpOptions::load_via_partition_root, _tableInfo::numParents, numTables, _tableInfo::parents, and relkind.

Referenced by getSchemaData().

316 {
317  DumpOptions *dopt = fout->dopt;
318  int i,
319  j;
320 
321  for (i = 0; i < numTables; i++)
322  {
323  bool find_parents = true;
324  bool mark_parents = true;
325 
326  /* Some kinds never have parents */
327  if (tblinfo[i].relkind == RELKIND_SEQUENCE ||
328  tblinfo[i].relkind == RELKIND_VIEW ||
329  tblinfo[i].relkind == RELKIND_MATVIEW)
330  continue;
331 
332  /*
333  * Normally, we don't bother computing anything for non-target tables,
334  * but if load-via-partition-root is specified, we gather information
335  * on every partition in the system so that getRootTableInfo can trace
336  * from any given to leaf partition all the way up to the root. (We
337  * don't need to mark them as interesting for getTableAttrs, though.)
338  */
339  if (!tblinfo[i].dobj.dump)
340  {
341  mark_parents = false;
342 
343  if (!dopt->load_via_partition_root ||
344  !tblinfo[i].ispartition)
345  find_parents = false;
346  }
347 
348  /* If needed, find all the immediate parent tables. */
349  if (find_parents)
350  findParentsByOid(&tblinfo[i], inhinfo, numInherits);
351 
352  /*
353  * If needed, mark the parents as interesting for getTableAttrs and
354  * getIndexes.
355  */
356  if (mark_parents)
357  {
358  int numParents = tblinfo[i].numParents;
359  TableInfo **parents = tblinfo[i].parents;
360 
361  for (j = 0; j < numParents; j++)
362  parents[j]->interesting = true;
363  }
364  }
365 }
struct _tableInfo ** parents
Definition: pg_dump.h:332
static void findParentsByOid(TableInfo *self, InhInfo *inhinfo, int numInherits)
Definition: common.c:1017
static int numTables
Definition: common.c:57
char relkind
Definition: pg_class.h:51
DumpOptions * dopt
Definition: pg_backup.h:183
int i
int load_via_partition_root
Definition: pg_backup.h:162

◆ getDumpableObjects()

void getDumpableObjects ( DumpableObject ***  objs,
int *  numObjs 
)

Definition at line 783 of file common.c.

References allocedDumpIds, i, and pg_malloc().

Referenced by findObjectByCatalogId(), getTableDataFKConstraints(), and main().

784 {
785  int i,
786  j;
787 
788  *objs = (DumpableObject **)
790  j = 0;
791  for (i = 1; i < allocedDumpIds; i++)
792  {
793  if (dumpIdMap[i])
794  (*objs)[j++] = dumpIdMap[i];
795  }
796  *numObjs = j;
797 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 622 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), flagInhIndexes(), and TopoSort().

623 {
624  return lastDumpId;
625 }
static DumpId lastDumpId
Definition: common.c:33

◆ getSchemaData()

TableInfo* getSchemaData ( Archive fout,
int *  numTablesPtr 
)

Definition at line 89 of file common.c.

References buildIndexArray(), Archive::dopt, flagInhAttrs(), flagInhIndexes(), flagInhTables(), g_verbose, getAccessMethods(), getAggregates(), getCasts(), getCollations(), getConstraints(), getConversions(), getDefaultACLs(), getEventTriggers(), getExtendedStatistics(), getExtensionMembership(), getExtensions(), getForeignDataWrappers(), getForeignServers(), getFuncs(), getIndexes(), getInherits(), getNamespaces(), getOpclasses(), getOperators(), getOpfamilies(), getOwnedSeqs(), getPolicies(), getProcLangs(), getPublications(), getPublicationTables(), getRules(), getSubscriptions(), getTableAttrs(), getTables(), getTransforms(), getTriggers(), getTSConfigurations(), getTSDictionaries(), getTSParsers(), getTSTemplates(), getTypes(), numCollations, numExtensions, numFuncs, numNamespaces, numOperators, numTables, numTypes, processExtensionTables(), and write_msg().

Referenced by main().

90 {
91  TableInfo *tblinfo;
93  FuncInfo *funinfo;
94  OprInfo *oprinfo;
95  CollInfo *collinfo;
96  NamespaceInfo *nspinfo;
97  ExtensionInfo *extinfo;
98  InhInfo *inhinfo;
99  int numAggregates;
100  int numInherits;
101  int numRules;
102  int numProcLangs;
103  int numCasts;
104  int numTransforms;
105  int numAccessMethods;
106  int numOpclasses;
107  int numOpfamilies;
108  int numConversions;
109  int numTSParsers;
110  int numTSTemplates;
111  int numTSDicts;
112  int numTSConfigs;
113  int numForeignDataWrappers;
114  int numForeignServers;
115  int numDefaultACLs;
116  int numEventTriggers;
117 
118  /*
119  * We must read extensions and extension membership info first, because
120  * extension membership needs to be consultable during decisions about
121  * whether other objects are to be dumped.
122  */
123  if (g_verbose)
124  write_msg(NULL, "reading extensions\n");
125  extinfo = getExtensions(fout, &numExtensions);
127 
128  if (g_verbose)
129  write_msg(NULL, "identifying extension members\n");
130  getExtensionMembership(fout, extinfo, numExtensions);
131 
132  if (g_verbose)
133  write_msg(NULL, "reading schemas\n");
134  nspinfo = getNamespaces(fout, &numNamespaces);
136 
137  /*
138  * getTables should be done as soon as possible, so as to minimize the
139  * window between starting our transaction and acquiring per-table locks.
140  * However, we have to do getNamespaces first because the tables get
141  * linked to their containing namespaces during getTables.
142  */
143  if (g_verbose)
144  write_msg(NULL, "reading user-defined tables\n");
145  tblinfo = getTables(fout, &numTables);
146  tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
147 
148  /* Do this after we've built tblinfoindex */
149  getOwnedSeqs(fout, tblinfo, numTables);
150 
151  if (g_verbose)
152  write_msg(NULL, "reading user-defined functions\n");
153  funinfo = getFuncs(fout, &numFuncs);
154  funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
155 
156  /* this must be after getTables and getFuncs */
157  if (g_verbose)
158  write_msg(NULL, "reading user-defined types\n");
159  typinfo = getTypes(fout, &numTypes);
160  typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo));
161 
162  /* this must be after getFuncs, too */
163  if (g_verbose)
164  write_msg(NULL, "reading procedural languages\n");
165  getProcLangs(fout, &numProcLangs);
166 
167  if (g_verbose)
168  write_msg(NULL, "reading user-defined aggregate functions\n");
169  getAggregates(fout, &numAggregates);
170 
171  if (g_verbose)
172  write_msg(NULL, "reading user-defined operators\n");
173  oprinfo = getOperators(fout, &numOperators);
174  oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo));
175 
176  if (g_verbose)
177  write_msg(NULL, "reading user-defined access methods\n");
178  getAccessMethods(fout, &numAccessMethods);
179 
180  if (g_verbose)
181  write_msg(NULL, "reading user-defined operator classes\n");
182  getOpclasses(fout, &numOpclasses);
183 
184  if (g_verbose)
185  write_msg(NULL, "reading user-defined operator families\n");
186  getOpfamilies(fout, &numOpfamilies);
187 
188  if (g_verbose)
189  write_msg(NULL, "reading user-defined text search parsers\n");
190  getTSParsers(fout, &numTSParsers);
191 
192  if (g_verbose)
193  write_msg(NULL, "reading user-defined text search templates\n");
194  getTSTemplates(fout, &numTSTemplates);
195 
196  if (g_verbose)
197  write_msg(NULL, "reading user-defined text search dictionaries\n");
198  getTSDictionaries(fout, &numTSDicts);
199 
200  if (g_verbose)
201  write_msg(NULL, "reading user-defined text search configurations\n");
202  getTSConfigurations(fout, &numTSConfigs);
203 
204  if (g_verbose)
205  write_msg(NULL, "reading user-defined foreign-data wrappers\n");
206  getForeignDataWrappers(fout, &numForeignDataWrappers);
207 
208  if (g_verbose)
209  write_msg(NULL, "reading user-defined foreign servers\n");
210  getForeignServers(fout, &numForeignServers);
211 
212  if (g_verbose)
213  write_msg(NULL, "reading default privileges\n");
214  getDefaultACLs(fout, &numDefaultACLs);
215 
216  if (g_verbose)
217  write_msg(NULL, "reading user-defined collations\n");
218  collinfo = getCollations(fout, &numCollations);
219  collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo));
220 
221  if (g_verbose)
222  write_msg(NULL, "reading user-defined conversions\n");
223  getConversions(fout, &numConversions);
224 
225  if (g_verbose)
226  write_msg(NULL, "reading type casts\n");
227  getCasts(fout, &numCasts);
228 
229  if (g_verbose)
230  write_msg(NULL, "reading transforms\n");
231  getTransforms(fout, &numTransforms);
232 
233  if (g_verbose)
234  write_msg(NULL, "reading table inheritance information\n");
235  inhinfo = getInherits(fout, &numInherits);
236 
237  if (g_verbose)
238  write_msg(NULL, "reading event triggers\n");
239  getEventTriggers(fout, &numEventTriggers);
240 
241  /* Identify extension configuration tables that should be dumped */
242  if (g_verbose)
243  write_msg(NULL, "finding extension tables\n");
244  processExtensionTables(fout, extinfo, numExtensions);
245 
246  /* Link tables to parents, mark parents of target tables interesting */
247  if (g_verbose)
248  write_msg(NULL, "finding inheritance relationships\n");
249  flagInhTables(fout, tblinfo, numTables, inhinfo, numInherits);
250 
251  if (g_verbose)
252  write_msg(NULL, "reading column info for interesting tables\n");
253  getTableAttrs(fout, tblinfo, numTables);
254 
255  if (g_verbose)
256  write_msg(NULL, "flagging inherited columns in subtables\n");
257  flagInhAttrs(fout->dopt, tblinfo, numTables);
258 
259  if (g_verbose)
260  write_msg(NULL, "reading indexes\n");
261  getIndexes(fout, tblinfo, numTables);
262 
263  if (g_verbose)
264  write_msg(NULL, "flagging indexes in partitioned tables\n");
265  flagInhIndexes(fout, tblinfo, numTables);
266 
267  if (g_verbose)
268  write_msg(NULL, "reading extended statistics\n");
269  getExtendedStatistics(fout);
270 
271  if (g_verbose)
272  write_msg(NULL, "reading constraints\n");
273  getConstraints(fout, tblinfo, numTables);
274 
275  if (g_verbose)
276  write_msg(NULL, "reading triggers\n");
277  getTriggers(fout, tblinfo, numTables);
278 
279  if (g_verbose)
280  write_msg(NULL, "reading rewrite rules\n");
281  getRules(fout, &numRules);
282 
283  if (g_verbose)
284  write_msg(NULL, "reading policies\n");
285  getPolicies(fout, tblinfo, numTables);
286 
287  if (g_verbose)
288  write_msg(NULL, "reading publications\n");
289  getPublications(fout);
290 
291  if (g_verbose)
292  write_msg(NULL, "reading publication membership\n");
293  getPublicationTables(fout, tblinfo, numTables);
294 
295  if (g_verbose)
296  write_msg(NULL, "reading subscriptions\n");
297  getSubscriptions(fout);
298 
299  *numTablesPtr = numTables;
300  return tblinfo;
301 }
FuncInfo * getFuncs(Archive *fout, int *numFuncs)
Definition: pg_dump.c:5591
static DumpableObject ** collinfoindex
Definition: common.c:54
static int numTypes
Definition: common.c:58
AggInfo * getAggregates(Archive *fout, int *numAggs)
Definition: pg_dump.c:5397
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:3881
CollInfo * getCollations(Archive *fout, int *numCollations)
Definition: pg_dump.c:5011
OprInfo * getOperators(Archive *fout, int *numOprs)
Definition: pg_dump.c:4928
static DumpableObject ** oprinfoindex
Definition: common.c:53
TransformInfo * getTransforms(Archive *fout, int *numTransforms)
Definition: pg_dump.c:7986
DefaultACLInfo * getDefaultACLs(Archive *fout, int *numDefaultACLs)
Definition: pg_dump.c:9245
static void flagInhTables(Archive *fout, TableInfo *tbinfo, int numTables, InhInfo *inhinfo, int numInherits)
Definition: common.c:314
static int numFuncs
Definition: common.c:59
AccessMethodInfo * getAccessMethods(Archive *fout, int *numAccessMethods)
Definition: pg_dump.c:5164
OpclassInfo * getOpclasses(Archive *fout, int *numOpclasses)
Definition: pg_dump.c:5238
TSConfigInfo * getTSConfigurations(Archive *fout, int *numTSConfigs)
Definition: pg_dump.c:8852
static int numTables
Definition: common.c:57
static DumpableObject ** buildIndexArray(void *objArray, int numObjs, Size objSize)
Definition: common.c:740
TSParserInfo * getTSParsers(Archive *fout, int *numTSParsers)
Definition: pg_dump.c:8601
static DumpableObject ** typinfoindex
Definition: common.c:51
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7114
static void flagInhIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition: pg_dump.c:6661
static int numOperators
Definition: common.c:60
DumpOptions * dopt
Definition: pg_backup.h:183
TableInfo * getTables(Archive *fout, int *numTables)
Definition: pg_dump.c:5827
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:3439
EventTriggerInfo * getEventTriggers(Archive *fout, int *numEventTriggers)
Definition: pg_dump.c:7604
static DumpableObject ** tblinfoindex
Definition: common.c:50
NamespaceInfo * getNamespaces(Archive *fout, int *numNamespaces)
Definition: pg_dump.c:4448
static int numExtensions
Definition: common.c:63
static int numNamespaces
Definition: common.c:62
RuleInfo * getRules(Archive *fout, int *numRules)
Definition: pg_dump.c:7296
FdwInfo * getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
Definition: pg_dump.c:8929
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:17547
void getSubscriptions(Archive *fout)
Definition: pg_dump.c:4029
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:6712
TSDictInfo * getTSDictionaries(Archive *fout, int *numTSDicts)
Definition: pg_dump.c:8692
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7409
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition: pg_dump.c:8083
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:6610
void write_msg(const char *modulename, const char *fmt,...)
ConvInfo * getConversions(Archive *fout, int *numConversions)
Definition: pg_dump.c:5091
OpfamilyInfo * getOpfamilies(Archive *fout, int *numOpfamilies)
Definition: pg_dump.c:5313
TSTemplateInfo * getTSTemplates(Archive *fout, int *numTSTemplates)
Definition: pg_dump.c:8776
static int numCollations
Definition: common.c:61
void getExtendedStatistics(Archive *fout)
Definition: pg_dump.c:7045
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition: pg_dump.c:4594
TypeInfo * getTypes(Archive *fout, int *numTypes)
Definition: pg_dump.c:4678
static DumpableObject ** extinfoindex
Definition: common.c:56
void getPublications(Archive *fout)
Definition: pg_dump.c:3697
ForeignServerInfo * getForeignServers(Archive *fout, int *numForeignServers)
Definition: pg_dump.c:9095
static DumpableObject ** funinfoindex
Definition: common.c:52
static DumpableObject ** nspinfoindex
Definition: common.c:55
ProcLangInfo * getProcLangs(Archive *fout, int *numProcLangs)
Definition: pg_dump.c:7695
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:17442
static void flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables)
Definition: common.c:463
bool g_verbose
Definition: pg_dump.c:93
CastInfo * getCasts(Archive *fout, int *numCasts)
Definition: pg_dump.c:7873

◆ parseOidArray()

void parseOidArray ( const char *  str,
Oid array,
int  arraysize 
)

Definition at line 1072 of file common.c.

References atooid, exit_nicely, InvalidOid, and write_msg().

Referenced by dumpFunc(), getAggregates(), getFuncs(), and getIndexes().

1073 {
1074  int j,
1075  argNum;
1076  char temp[100];
1077  char s;
1078 
1079  argNum = 0;
1080  j = 0;
1081  for (;;)
1082  {
1083  s = *str++;
1084  if (s == ' ' || s == '\0')
1085  {
1086  if (j > 0)
1087  {
1088  if (argNum >= arraysize)
1089  {
1090  write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str);
1091  exit_nicely(1);
1092  }
1093  temp[j] = '\0';
1094  array[argNum++] = atooid(temp);
1095  j = 0;
1096  }
1097  if (s == '\0')
1098  break;
1099  }
1100  else
1101  {
1102  if (!(isdigit((unsigned char) s) || s == '-') ||
1103  j >= sizeof(temp) - 1)
1104  {
1105  write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str);
1106  exit_nicely(1);
1107  }
1108  temp[j++] = s;
1109  }
1110  }
1111 
1112  while (argNum < arraysize)
1113  array[argNum++] = InvalidOid;
1114 }
#define atooid(x)
Definition: postgres_ext.h:42
#define exit_nicely(code)
Definition: pg_dumpall.c:89
#define InvalidOid
Definition: postgres_ext.h:36
void write_msg(const char *modulename, const char *fmt,...)

◆ removeObjectDependency()

void removeObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

◆ setExtensionMembership()

void setExtensionMembership ( ExtensionMemberId extmems,
int  nextmems 
)

Definition at line 941 of file common.c.

References ExtensionMemberIdCompare(), numextmembers, and qsort.

Referenced by getExtensionMembership().

942 {
943  /* Sort array in preparation for binary searches */
944  if (nextmems > 1)
945  qsort((void *) extmems, nextmems, sizeof(ExtensionMemberId),
947  /* And save */
948  extmembers = extmems;
949  numextmembers = nextmems;
950 }
static int ExtensionMemberIdCompare(const void *p1, const void *p2)
Definition: common.c:995
static ExtensionMemberId * extmembers
Definition: common.c:66
static int numextmembers
Definition: common.c:67
#define qsort(a, b, c, d)
Definition: port.h:421

◆ strInArray()

static int strInArray ( const char *  pattern,
char **  arr,
int  arr_size 
)
static

Definition at line 1125 of file common.c.

References i.

Referenced by flagInhAttrs().

1126 {
1127  int i;
1128 
1129  for (i = 0; i < arr_size; i++)
1130  {
1131  if (strcmp(pattern, arr[i]) == 0)
1132  return i;
1133  }
1134  return -1;
1135 }
int i

Variable Documentation

◆ allocedDumpIds

int allocedDumpIds = 0
static

Definition at line 32 of file common.c.

Referenced by AssignDumpId(), findObjectByDumpId(), and getDumpableObjects().

◆ catalogIdMap

DumpableObject** catalogIdMap = NULL
static

Definition at line 39 of file common.c.

Referenced by findObjectByCatalogId().

◆ catalogIdMapValid

bool catalogIdMapValid = false
static

Definition at line 38 of file common.c.

Referenced by AssignDumpId(), and findObjectByCatalogId().

◆ collinfoindex

DumpableObject** collinfoindex
static

Definition at line 54 of file common.c.

◆ dumpIdMap

DumpableObject** dumpIdMap = NULL
static

Definition at line 31 of file common.c.

◆ extinfoindex

DumpableObject** extinfoindex
static

Definition at line 56 of file common.c.

◆ extmembers

ExtensionMemberId* extmembers
static

Definition at line 66 of file common.c.

Referenced by findOwningExtension(), and getExtensionMembership().

◆ funinfoindex

DumpableObject** funinfoindex
static

Definition at line 52 of file common.c.

◆ lastDumpId

DumpId lastDumpId = 0
static

Definition at line 33 of file common.c.

Referenced by AssignDumpId(), createDumpId(), and getMaxDumpId().

◆ nspinfoindex

DumpableObject** nspinfoindex
static

Definition at line 55 of file common.c.

◆ numCatalogIds

int numCatalogIds = 0
static

Definition at line 40 of file common.c.

Referenced by findObjectByCatalogId().

◆ numCollations

int numCollations
static

Definition at line 61 of file common.c.

Referenced by findCollationByOid(), and getSchemaData().

◆ numExtensions

int numExtensions
static

Definition at line 63 of file common.c.

Referenced by findExtensionByOid(), getSchemaData(), and processExtensionTables().

◆ numextmembers

int numextmembers
static

Definition at line 67 of file common.c.

Referenced by findOwningExtension(), and setExtensionMembership().

◆ numFuncs

int numFuncs
static

Definition at line 59 of file common.c.

Referenced by findFuncByOid(), and getSchemaData().

◆ numNamespaces

int numNamespaces
static

Definition at line 62 of file common.c.

Referenced by findNamespaceByOid(), and getSchemaData().

◆ numOperators

int numOperators
static

Definition at line 60 of file common.c.

Referenced by findOprByOid(), and getSchemaData().

◆ numTables

◆ numTypes

int numTypes
static

Definition at line 58 of file common.c.

Referenced by findTypeByOid(), and getSchemaData().

◆ oprinfoindex

DumpableObject** oprinfoindex
static

Definition at line 53 of file common.c.

◆ tblinfoindex

DumpableObject** tblinfoindex
static

Definition at line 50 of file common.c.

◆ typinfoindex

DumpableObject** typinfoindex
static

Definition at line 51 of file common.c.