PostgreSQL Source Code  git master
common.c File Reference
#include "postgres_fe.h"
#include <ctype.h>
#include "catalog/pg_class_d.h"
#include "fe_utils/string_utils.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
#include "pg_dump.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 785 of file common.c.

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

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

786 {
787  if (dobj->nDeps >= dobj->allocDeps)
788  {
789  if (dobj->allocDeps <= 0)
790  {
791  dobj->allocDeps = 16;
792  dobj->dependencies = (DumpId *)
793  pg_malloc(dobj->allocDeps * sizeof(DumpId));
794  }
795  else
796  {
797  dobj->allocDeps *= 2;
798  dobj->dependencies = (DumpId *)
799  pg_realloc(dobj->dependencies,
800  dobj->allocDeps * sizeof(DumpId));
801  }
802  }
803  dobj->dependencies[dobj->nDeps++] = refId;
804 }
int DumpId
Definition: pg_backup.h:234
DumpId * dependencies
Definition: pg_dump.h:136
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 545 of file common.c.

References _dumpableObject::allocDeps, allocedDumpIds, catalogIdMapValid, _dumpableObject::dependencies, _dumpableObject::depends_on_ext, _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().

546 {
547  dobj->dumpId = ++lastDumpId;
548  dobj->name = NULL; /* must be set later */
549  dobj->namespace = NULL; /* may be set later */
550  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
551  dobj->ext_member = false; /* default assumption */
552  dobj->depends_on_ext = false; /* default assumption */
553  dobj->dependencies = NULL;
554  dobj->nDeps = 0;
555  dobj->allocDeps = 0;
556 
557  while (dobj->dumpId >= allocedDumpIds)
558  {
559  int newAlloc;
560 
561  if (allocedDumpIds <= 0)
562  {
563  newAlloc = 256;
565  pg_malloc(newAlloc * sizeof(DumpableObject *));
566  }
567  else
568  {
569  newAlloc = allocedDumpIds * 2;
571  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
572  }
573  memset(dumpIdMap + allocedDumpIds, 0,
574  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
575  allocedDumpIds = newAlloc;
576  }
577  dumpIdMap[dobj->dumpId] = dobj;
578 
579  /* mark catalogIdMap invalid, but don't rebuild it yet */
580  catalogIdMapValid = false;
581 }
char * name
Definition: pg_dump.h:130
static int allocedDumpIds
Definition: common.c:30
DumpComponents dump
Definition: pg_dump.h:131
static DumpId lastDumpId
Definition: common.c:31
static DumpableObject ** dumpIdMap
Definition: common.c:29
DumpId * dependencies
Definition: pg_dump.h:136
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:129
bool ext_member
Definition: pg_dump.h:134
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
bool depends_on_ext
Definition: pg_dump.h:135
static bool catalogIdMapValid
Definition: common.c:36
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:96

◆ buildIndexArray()

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

Definition at line 717 of file common.c.

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

Referenced by flagInhIndexes(), and getSchemaData().

718 {
719  DumpableObject **ptrs;
720  int i;
721 
722  if (numObjs <= 0)
723  return NULL;
724 
725  ptrs = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
726  for (i = 0; i < numObjs; i++)
727  ptrs[i] = (DumpableObject *) ((char *) objArray + i * objSize);
728 
729  /* We can use DOCatalogIdCompare to sort since its first key is OID */
730  if (numObjs > 1)
731  qsort((void *) ptrs, numObjs, sizeof(DumpableObject *),
733 
734  return ptrs;
735 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:741
int i
#define qsort(a, b, c, d)
Definition: port.h:475

◆ createDumpId()

◆ DOCatalogIdCompare()

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

Definition at line 741 of file common.c.

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

Referenced by buildIndexArray(), and findObjectByCatalogId().

742 {
743  const DumpableObject *obj1 = *(DumpableObject *const *) p1;
744  const DumpableObject *obj2 = *(DumpableObject *const *) p2;
745  int cmpval;
746 
747  /*
748  * Compare OID first since it's usually unique, whereas there will only be
749  * a few distinct values of tableoid.
750  */
751  cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
752  if (cmpval == 0)
753  cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
754  return cmpval;
755 }
Oid tableoid
Definition: pg_backup.h:230
#define oidcmp(x, y)
Definition: pg_dump.h:20
CatalogId catId
Definition: pg_dump.h:128

◆ ExtensionMemberIdCompare()

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

Definition at line 975 of file common.c.

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

Referenced by setExtensionMembership().

976 {
977  const ExtensionMemberId *obj1 = (const ExtensionMemberId *) p1;
978  const ExtensionMemberId *obj2 = (const ExtensionMemberId *) p2;
979  int cmpval;
980 
981  /*
982  * Compare OID first since it's usually unique, whereas there will only be
983  * a few distinct values of tableoid.
984  */
985  cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
986  if (cmpval == 0)
987  cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
988  return cmpval;
989 }
Oid tableoid
Definition: pg_backup.h:230
#define oidcmp(x, y)
Definition: pg_dump.h:20
CatalogId catId
Definition: pg_dump.h:640

◆ findCollationByOid()

CollInfo* findCollationByOid ( Oid  oid)

Definition at line 876 of file common.c.

References findObjectByOid(), and numCollations.

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

877 {
879 }
static DumpableObject ** collinfoindex
Definition: common.c:52
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numCollations
Definition: common.c:59

◆ findExtensionByOid()

ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 898 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

899 {
901 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numExtensions
Definition: common.c:61
static DumpableObject ** extinfoindex
Definition: common.c:54

◆ findFuncByOid()

FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 854 of file common.c.

References findObjectByOid(), and numFuncs.

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

855 {
856  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
857 }
static int numFuncs
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static DumpableObject ** funinfoindex
Definition: common.c:50

◆ findIndexByOid()

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

Definition at line 911 of file common.c.

References findObjectByOid().

Referenced by flagInhIndexes().

912 {
913  return (IndxInfo *) findObjectByOid(oid, idxinfoindex, numIndexes);
914 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679

◆ findNamespaceByOid()

NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 887 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

888 {
890 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numNamespaces
Definition: common.c:60
static DumpableObject ** nspinfoindex
Definition: common.c:53

◆ findObjectByCatalogId()

DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 628 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

629 {
630  DumpableObject **low;
631  DumpableObject **high;
632 
633  if (!catalogIdMapValid)
634  {
635  if (catalogIdMap)
638  if (numCatalogIds > 1)
639  qsort((void *) catalogIdMap, numCatalogIds,
641  catalogIdMapValid = true;
642  }
643 
644  /*
645  * We could use bsearch() here, but the notational cruft of calling
646  * bsearch is nearly as bad as doing it ourselves; and the generalized
647  * bsearch function is noticeably slower as well.
648  */
649  if (numCatalogIds <= 0)
650  return NULL;
651  low = catalogIdMap;
652  high = catalogIdMap + (numCatalogIds - 1);
653  while (low <= high)
654  {
655  DumpableObject **middle;
656  int difference;
657 
658  middle = low + (high - low) / 2;
659  /* comparison must match DOCatalogIdCompare, below */
660  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
661  if (difference == 0)
662  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
663  if (difference == 0)
664  return *middle;
665  else if (difference < 0)
666  low = middle + 1;
667  else
668  high = middle - 1;
669  }
670  return NULL;
671 }
Oid tableoid
Definition: pg_backup.h:230
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:741
static int numCatalogIds
Definition: common.c:38
Datum difference(PG_FUNCTION_ARGS)
#define free(a)
Definition: header.h:65
static DumpableObject ** catalogIdMap
Definition: common.c:37
static bool catalogIdMapValid
Definition: common.c:36
#define qsort(a, b, c, d)
Definition: port.h:475
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:763

◆ findObjectByDumpId()

DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 610 of file common.c.

References allocedDumpIds.

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

611 {
612  if (dumpId <= 0 || dumpId >= allocedDumpIds)
613  return NULL; /* out of range? */
614  return dumpIdMap[dumpId];
615 }
static int allocedDumpIds
Definition: common.c:30
static DumpableObject ** dumpIdMap
Definition: common.c:29

◆ findObjectByOid()

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

Definition at line 679 of file common.c.

References difference(), and oidcmp.

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

680 {
681  DumpableObject **low;
682  DumpableObject **high;
683 
684  /*
685  * This is the same as findObjectByCatalogId except we assume we need not
686  * look at table OID because the objects are all the same type.
687  *
688  * We could use bsearch() here, but the notational cruft of calling
689  * bsearch is nearly as bad as doing it ourselves; and the generalized
690  * bsearch function is noticeably slower as well.
691  */
692  if (numObjs <= 0)
693  return NULL;
694  low = indexArray;
695  high = indexArray + (numObjs - 1);
696  while (low <= high)
697  {
698  DumpableObject **middle;
699  int difference;
700 
701  middle = low + (high - low) / 2;
702  difference = oidcmp((*middle)->catId.oid, oid);
703  if (difference == 0)
704  return *middle;
705  else if (difference < 0)
706  low = middle + 1;
707  else
708  high = middle - 1;
709  }
710  return NULL;
711 }
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)

◆ findOprByOid()

OprInfo* findOprByOid ( Oid  oid)

Definition at line 865 of file common.c.

References findObjectByOid(), and numOperators.

Referenced by getFormattedOperatorName().

866 {
868 }
static DumpableObject ** oprinfoindex
Definition: common.c:51
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static int numOperators
Definition: common.c:58

◆ findOwningExtension()

ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 937 of file common.c.

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

Referenced by checkExtensionMembership().

938 {
939  ExtensionMemberId *low;
940  ExtensionMemberId *high;
941 
942  /*
943  * We could use bsearch() here, but the notational cruft of calling
944  * bsearch is nearly as bad as doing it ourselves; and the generalized
945  * bsearch function is noticeably slower as well.
946  */
947  if (numextmembers <= 0)
948  return NULL;
949  low = extmembers;
950  high = extmembers + (numextmembers - 1);
951  while (low <= high)
952  {
953  ExtensionMemberId *middle;
954  int difference;
955 
956  middle = low + (high - low) / 2;
957  /* comparison must match ExtensionMemberIdCompare, below */
958  difference = oidcmp(middle->catId.oid, catalogId.oid);
959  if (difference == 0)
960  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
961  if (difference == 0)
962  return middle->ext;
963  else if (difference < 0)
964  low = middle + 1;
965  else
966  high = middle - 1;
967  }
968  return NULL;
969 }
ExtensionInfo * ext
Definition: pg_dump.h:641
Oid tableoid
Definition: pg_backup.h:230
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
static ExtensionMemberId * extmembers
Definition: common.c:64
static int numextmembers
Definition: common.c:65
CatalogId catId
Definition: pg_dump.h:640

◆ findParentsByOid()

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

Definition at line 997 of file common.c.

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

Referenced by flagInhTables().

999 {
1000  Oid oid = self->dobj.catId.oid;
1001  int i,
1002  j;
1003  int numParents;
1004 
1005  numParents = 0;
1006  for (i = 0; i < numInherits; i++)
1007  {
1008  if (inhinfo[i].inhrelid == oid)
1009  numParents++;
1010  }
1011 
1012  self->numParents = numParents;
1013 
1014  if (numParents > 0)
1015  {
1016  self->parents = (TableInfo **)
1017  pg_malloc(sizeof(TableInfo *) * numParents);
1018  j = 0;
1019  for (i = 0; i < numInherits; i++)
1020  {
1021  if (inhinfo[i].inhrelid == oid)
1022  {
1023  TableInfo *parent;
1024 
1025  parent = findTableByOid(inhinfo[i].inhparent);
1026  if (parent == NULL)
1027  {
1028  pg_log_error("failed sanity check, parent OID %u of table \"%s\" (OID %u) not found",
1029  inhinfo[i].inhparent,
1030  self->dobj.name,
1031  oid);
1032  exit_nicely(1);
1033  }
1034  self->parents[j++] = parent;
1035  }
1036  }
1037  }
1038  else
1039  self->parents = NULL;
1040 }
char * name
Definition: pg_dump.h:130
TableInfo * findTableByOid(Oid oid)
Definition: common.c:832
struct _tableInfo ** parents
Definition: pg_dump.h:332
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define pg_log_error(...)
Definition: logging.h:80
unsigned int Oid
Definition: postgres_ext.h:31
DumpableObject dobj
Definition: pg_dump.h:259
#define exit_nicely(code)
Definition: pg_dumpall.c:96
int i

◆ findTableByOid()

TableInfo* findTableByOid ( Oid  oid)

Definition at line 832 of file common.c.

References findObjectByOid(), and numTables.

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

833 {
835 }
static int numTables
Definition: common.c:55
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static DumpableObject ** tblinfoindex
Definition: common.c:48

◆ findTypeByOid()

TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 843 of file common.c.

References findObjectByOid(), and numTypes.

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

844 {
845  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
846 }
static int numTypes
Definition: common.c:56
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:679
static DumpableObject ** typinfoindex
Definition: common.c:49

◆ flagInhAttrs()

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

Definition at line 439 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().

440 {
441  int i,
442  j,
443  k;
444 
445  for (i = 0; i < numTables; i++)
446  {
447  TableInfo *tbinfo = &(tblinfo[i]);
448  int numParents;
449  TableInfo **parents;
450 
451  /* Some kinds never have parents */
452  if (tbinfo->relkind == RELKIND_SEQUENCE ||
453  tbinfo->relkind == RELKIND_VIEW ||
454  tbinfo->relkind == RELKIND_MATVIEW)
455  continue;
456 
457  /* Don't bother computing anything for non-target tables, either */
458  if (!tbinfo->dobj.dump)
459  continue;
460 
461  numParents = tbinfo->numParents;
462  parents = tbinfo->parents;
463 
464  if (numParents == 0)
465  continue; /* nothing to see here, move along */
466 
467  /* For each column, search for matching column names in parent(s) */
468  for (j = 0; j < tbinfo->numatts; j++)
469  {
470  bool foundNotNull; /* Attr was NOT NULL in a parent */
471  bool foundDefault; /* Found a default in a parent */
472 
473  /* no point in examining dropped columns */
474  if (tbinfo->attisdropped[j])
475  continue;
476 
477  foundNotNull = false;
478  foundDefault = false;
479  for (k = 0; k < numParents; k++)
480  {
481  TableInfo *parent = parents[k];
482  int inhAttrInd;
483 
484  inhAttrInd = strInArray(tbinfo->attnames[j],
485  parent->attnames,
486  parent->numatts);
487  if (inhAttrInd >= 0)
488  {
489  foundNotNull |= parent->notnull[inhAttrInd];
490  foundDefault |= (parent->attrdefs[inhAttrInd] != NULL);
491  }
492  }
493 
494  /* Remember if we found inherited NOT NULL */
495  tbinfo->inhNotNull[j] = foundNotNull;
496 
497  /* Manufacture a DEFAULT NULL clause if necessary */
498  if (foundDefault && tbinfo->attrdefs[j] == NULL)
499  {
500  AttrDefInfo *attrDef;
501 
502  attrDef = (AttrDefInfo *) pg_malloc(sizeof(AttrDefInfo));
503  attrDef->dobj.objType = DO_ATTRDEF;
504  attrDef->dobj.catId.tableoid = 0;
505  attrDef->dobj.catId.oid = 0;
506  AssignDumpId(&attrDef->dobj);
507  attrDef->dobj.name = pg_strdup(tbinfo->dobj.name);
508  attrDef->dobj.namespace = tbinfo->dobj.namespace;
509  attrDef->dobj.dump = tbinfo->dobj.dump;
510 
511  attrDef->adtable = tbinfo;
512  attrDef->adnum = j + 1;
513  attrDef->adef_expr = pg_strdup("NULL");
514 
515  /* Will column be dumped explicitly? */
516  if (shouldPrintColumn(dopt, tbinfo, j))
517  {
518  attrDef->separate = false;
519  /* No dependency needed: NULL cannot have dependencies */
520  }
521  else
522  {
523  /* column will be suppressed, print default separately */
524  attrDef->separate = true;
525  /* ensure it comes out after the table */
526  addObjectDependency(&attrDef->dobj,
527  tbinfo->dobj.dumpId);
528  }
529 
530  tbinfo->attrdefs[j] = attrDef;
531  }
532  }
533  }
534 }
char * name
Definition: pg_dump.h:130
struct _tableInfo ** parents
Definition: pg_dump.h:332
char relkind
Definition: pg_dump.h:265
DumpComponents dump
Definition: pg_dump.h:131
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno)
Definition: pg_dump.c:8865
bool * inhNotNull
Definition: pg_dump.h:320
DumpId dumpId
Definition: pg_dump.h:129
static int numTables
Definition: common.c:55
char ** attnames
Definition: pg_dump.h:303
DumpableObject dobj
Definition: pg_dump.h:259
static int strInArray(const char *pattern, char **arr, int arr_size)
Definition: common.c:1105
bool separate
Definition: pg_dump.h:346
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
bool * attisdropped
Definition: pg_dump.h:309
TableInfo * adtable
Definition: pg_dump.h:343
int numatts
Definition: pg_dump.h:302
bool * notnull
Definition: pg_dump.h:319
DumpableObject dobj
Definition: pg_dump.h:342
struct _attrDefInfo ** attrdefs
Definition: pg_dump.h:321
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:785
CatalogId catId
Definition: pg_dump.h:128
int i
int numParents
Definition: pg_dump.h:331
DumpableObjectType objType
Definition: pg_dump.h:127
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 332 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, _indxInfo::indextable, _dumpableObject::name, _tableInfo::numIndexes, numTables, _dumpableObject::objType, CatalogId::oid, _indxInfo::parentidx, _indexAttachInfo::parentIdx, _tableInfo::parents, _indxInfo::partattaches, _indexAttachInfo::partitionIdx, pg_free(), pg_malloc0(), pg_strdup(), simple_ptr_list_append(), and CatalogId::tableoid.

333 {
334  int i,
335  j,
336  k;
337  DumpableObject ***parentIndexArray;
338 
339  parentIndexArray = (DumpableObject ***)
340  pg_malloc0(getMaxDumpId() * sizeof(DumpableObject **));
341 
342  for (i = 0; i < numTables; i++)
343  {
344  TableInfo *parenttbl;
345  IndexAttachInfo *attachinfo;
346 
347  if (!tblinfo[i].ispartition || tblinfo[i].numParents == 0)
348  continue;
349 
350  Assert(tblinfo[i].numParents == 1);
351  parenttbl = tblinfo[i].parents[0];
352 
353  /*
354  * We need access to each parent table's index list, but there is no
355  * index to cover them outside of this function. To avoid having to
356  * sort every parent table's indexes each time we come across each of
357  * its partitions, create an indexed array for each parent the first
358  * time it is required.
359  */
360  if (parentIndexArray[parenttbl->dobj.dumpId] == NULL)
361  parentIndexArray[parenttbl->dobj.dumpId] =
362  buildIndexArray(parenttbl->indexes,
363  parenttbl->numIndexes,
364  sizeof(IndxInfo));
365 
366  attachinfo = (IndexAttachInfo *)
367  pg_malloc0(tblinfo[i].numIndexes * sizeof(IndexAttachInfo));
368  for (j = 0, k = 0; j < tblinfo[i].numIndexes; j++)
369  {
370  IndxInfo *index = &(tblinfo[i].indexes[j]);
371  IndxInfo *parentidx;
372 
373  if (index->parentidx == 0)
374  continue;
375 
376  parentidx = findIndexByOid(index->parentidx,
377  parentIndexArray[parenttbl->dobj.dumpId],
378  parenttbl->numIndexes);
379  if (parentidx == NULL)
380  continue;
381 
382  attachinfo[k].dobj.objType = DO_INDEX_ATTACH;
383  attachinfo[k].dobj.catId.tableoid = 0;
384  attachinfo[k].dobj.catId.oid = 0;
385  AssignDumpId(&attachinfo[k].dobj);
386  attachinfo[k].dobj.name = pg_strdup(index->dobj.name);
387  attachinfo[k].dobj.namespace = index->indextable->dobj.namespace;
388  attachinfo[k].parentIdx = parentidx;
389  attachinfo[k].partitionIdx = index;
390 
391  /*
392  * We must state the DO_INDEX_ATTACH object's dependencies
393  * explicitly, since it will not match anything in pg_depend.
394  *
395  * Give it dependencies on both the partition index and the parent
396  * index, so that it will not be executed till both of those
397  * exist. (There's no need to care what order those are created
398  * in.)
399  *
400  * In addition, give it dependencies on the indexes' underlying
401  * tables. This does nothing of great value so far as serial
402  * restore ordering goes, but it ensures that a parallel restore
403  * will not try to run the ATTACH concurrently with other
404  * operations on those tables.
405  */
406  addObjectDependency(&attachinfo[k].dobj, index->dobj.dumpId);
407  addObjectDependency(&attachinfo[k].dobj, parentidx->dobj.dumpId);
408  addObjectDependency(&attachinfo[k].dobj,
409  index->indextable->dobj.dumpId);
410  addObjectDependency(&attachinfo[k].dobj,
411  parentidx->indextable->dobj.dumpId);
412 
413  /* keep track of the list of partitions in the parent index */
414  simple_ptr_list_append(&parentidx->partattaches, &attachinfo[k].dobj);
415 
416  k++;
417  }
418  }
419 
420  for (i = 0; i < numTables; i++)
421  if (parentIndexArray[i])
422  pg_free(parentIndexArray[i]);
423  pg_free(parentIndexArray);
424 }
char * name
Definition: pg_dump.h:130
struct _tableInfo ** parents
Definition: pg_dump.h:332
Oid tableoid
Definition: pg_backup.h:230
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:545
DumpId dumpId
Definition: pg_dump.h:129
static int numTables
Definition: common.c:55
DumpableObject dobj
Definition: pg_dump.h:259
Oid parentidx
Definition: pg_dump.h:371
static DumpableObject ** buildIndexArray(void *objArray, int numObjs, Size objSize)
Definition: common.c:717
Definition: type.h:89
DumpableObject dobj
Definition: pg_dump.h:380
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
TableInfo * indextable
Definition: pg_dump.h:359
IndxInfo * partitionIdx
Definition: pg_dump.h:382
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static IndxInfo * findIndexByOid(Oid oid, DumpableObject **idxinfoindex, int numIndexes)
Definition: common.c:911
SimplePtrList partattaches
Definition: pg_dump.h:372
int numIndexes
Definition: pg_dump.h:333
DumpId getMaxDumpId(void)
Definition: common.c:599
#define Assert(condition)
Definition: c.h:745
IndxInfo * parentIdx
Definition: pg_dump.h:381
void pg_free(void *ptr)
Definition: fe_memutils.c:105
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:785
CatalogId catId
Definition: pg_dump.h:128
struct _indxInfo * indexes
Definition: pg_dump.h:334
DumpableObject dobj
Definition: pg_dump.h:358
void simple_ptr_list_append(SimplePtrList *list, void *ptr)
Definition: simple_list.c:162
int i
DumpableObjectType objType
Definition: pg_dump.h:127

◆ flagInhTables()

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

Definition at line 273 of file common.c.

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

Referenced by getSchemaData().

275 {
276  DumpOptions *dopt = fout->dopt;
277  int i,
278  j;
279 
280  for (i = 0; i < numTables; i++)
281  {
282  bool find_parents = true;
283  bool mark_parents = true;
284 
285  /* Some kinds never have parents */
286  if (tblinfo[i].relkind == RELKIND_SEQUENCE ||
287  tblinfo[i].relkind == RELKIND_VIEW ||
288  tblinfo[i].relkind == RELKIND_MATVIEW)
289  continue;
290 
291  /*
292  * Normally, we don't bother computing anything for non-target tables,
293  * but if load-via-partition-root is specified, we gather information
294  * on every partition in the system so that getRootTableInfo can trace
295  * from any given to leaf partition all the way up to the root. (We
296  * don't need to mark them as interesting for getTableAttrs, though.)
297  */
298  if (!tblinfo[i].dobj.dump)
299  {
300  mark_parents = false;
301 
302  if (!dopt->load_via_partition_root ||
303  !tblinfo[i].ispartition)
304  find_parents = false;
305  }
306 
307  /* If needed, find all the immediate parent tables. */
308  if (find_parents)
309  findParentsByOid(&tblinfo[i], inhinfo, numInherits);
310 
311  /*
312  * If needed, mark the parents as interesting for getTableAttrs and
313  * getIndexes.
314  */
315  if (mark_parents)
316  {
317  int numParents = tblinfo[i].numParents;
318  TableInfo **parents = tblinfo[i].parents;
319 
320  for (j = 0; j < numParents; j++)
321  parents[j]->interesting = true;
322  }
323  }
324 }
struct _tableInfo ** parents
Definition: pg_dump.h:332
static void findParentsByOid(TableInfo *self, InhInfo *inhinfo, int numInherits)
Definition: common.c:997
static int numTables
Definition: common.c:55
DumpOptions * dopt
Definition: pg_backup.h:182
int i
int load_via_partition_root
Definition: pg_backup.h:160

◆ getDumpableObjects()

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

Definition at line 763 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

764 {
765  int i,
766  j;
767 
768  *objs = (DumpableObject **)
770  j = 0;
771  for (i = 1; i < allocedDumpIds; i++)
772  {
773  if (dumpIdMap[i])
774  (*objs)[j++] = dumpIdMap[i];
775  }
776  *numObjs = j;
777 }
static int allocedDumpIds
Definition: common.c:30
static DumpableObject ** dumpIdMap
Definition: common.c:29
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
int i

◆ getMaxDumpId()

DumpId getMaxDumpId ( void  )

Definition at line 599 of file common.c.

References lastDumpId.

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

600 {
601  return lastDumpId;
602 }
static DumpId lastDumpId
Definition: common.c:31

◆ getSchemaData()

TableInfo* getSchemaData ( Archive fout,
int *  numTablesPtr 
)

Definition at line 87 of file common.c.

References buildIndexArray(), Archive::dopt, flagInhAttrs(), flagInhIndexes(), flagInhTables(), 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, pg_log_info, and processExtensionTables().

Referenced by main().

88 {
89  TableInfo *tblinfo;
91  FuncInfo *funinfo;
92  OprInfo *oprinfo;
93  CollInfo *collinfo;
94  NamespaceInfo *nspinfo;
95  ExtensionInfo *extinfo;
96  InhInfo *inhinfo;
97  int numAggregates;
98  int numInherits;
99  int numRules;
100  int numProcLangs;
101  int numCasts;
102  int numTransforms;
103  int numAccessMethods;
104  int numOpclasses;
105  int numOpfamilies;
106  int numConversions;
107  int numTSParsers;
108  int numTSTemplates;
109  int numTSDicts;
110  int numTSConfigs;
111  int numForeignDataWrappers;
112  int numForeignServers;
113  int numDefaultACLs;
114  int numEventTriggers;
115 
116  /*
117  * We must read extensions and extension membership info first, because
118  * extension membership needs to be consultable during decisions about
119  * whether other objects are to be dumped.
120  */
121  pg_log_info("reading extensions");
122  extinfo = getExtensions(fout, &numExtensions);
124 
125  pg_log_info("identifying extension members");
126  getExtensionMembership(fout, extinfo, numExtensions);
127 
128  pg_log_info("reading schemas");
129  nspinfo = getNamespaces(fout, &numNamespaces);
131 
132  /*
133  * getTables should be done as soon as possible, so as to minimize the
134  * window between starting our transaction and acquiring per-table locks.
135  * However, we have to do getNamespaces first because the tables get
136  * linked to their containing namespaces during getTables.
137  */
138  pg_log_info("reading user-defined tables");
139  tblinfo = getTables(fout, &numTables);
140  tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
141 
142  /* Do this after we've built tblinfoindex */
143  getOwnedSeqs(fout, tblinfo, numTables);
144 
145  pg_log_info("reading user-defined functions");
146  funinfo = getFuncs(fout, &numFuncs);
147  funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
148 
149  /* this must be after getTables and getFuncs */
150  pg_log_info("reading user-defined types");
151  typinfo = getTypes(fout, &numTypes);
152  typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo));
153 
154  /* this must be after getFuncs, too */
155  pg_log_info("reading procedural languages");
156  getProcLangs(fout, &numProcLangs);
157 
158  pg_log_info("reading user-defined aggregate functions");
159  getAggregates(fout, &numAggregates);
160 
161  pg_log_info("reading user-defined operators");
162  oprinfo = getOperators(fout, &numOperators);
163  oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo));
164 
165  pg_log_info("reading user-defined access methods");
166  getAccessMethods(fout, &numAccessMethods);
167 
168  pg_log_info("reading user-defined operator classes");
169  getOpclasses(fout, &numOpclasses);
170 
171  pg_log_info("reading user-defined operator families");
172  getOpfamilies(fout, &numOpfamilies);
173 
174  pg_log_info("reading user-defined text search parsers");
175  getTSParsers(fout, &numTSParsers);
176 
177  pg_log_info("reading user-defined text search templates");
178  getTSTemplates(fout, &numTSTemplates);
179 
180  pg_log_info("reading user-defined text search dictionaries");
181  getTSDictionaries(fout, &numTSDicts);
182 
183  pg_log_info("reading user-defined text search configurations");
184  getTSConfigurations(fout, &numTSConfigs);
185 
186  pg_log_info("reading user-defined foreign-data wrappers");
187  getForeignDataWrappers(fout, &numForeignDataWrappers);
188 
189  pg_log_info("reading user-defined foreign servers");
190  getForeignServers(fout, &numForeignServers);
191 
192  pg_log_info("reading default privileges");
193  getDefaultACLs(fout, &numDefaultACLs);
194 
195  pg_log_info("reading user-defined collations");
196  collinfo = getCollations(fout, &numCollations);
197  collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo));
198 
199  pg_log_info("reading user-defined conversions");
200  getConversions(fout, &numConversions);
201 
202  pg_log_info("reading type casts");
203  getCasts(fout, &numCasts);
204 
205  pg_log_info("reading transforms");
206  getTransforms(fout, &numTransforms);
207 
208  pg_log_info("reading table inheritance information");
209  inhinfo = getInherits(fout, &numInherits);
210 
211  pg_log_info("reading event triggers");
212  getEventTriggers(fout, &numEventTriggers);
213 
214  /* Identify extension configuration tables that should be dumped */
215  pg_log_info("finding extension tables");
216  processExtensionTables(fout, extinfo, numExtensions);
217 
218  /* Link tables to parents, mark parents of target tables interesting */
219  pg_log_info("finding inheritance relationships");
220  flagInhTables(fout, tblinfo, numTables, inhinfo, numInherits);
221 
222  pg_log_info("reading column info for interesting tables");
223  getTableAttrs(fout, tblinfo, numTables);
224 
225  pg_log_info("flagging inherited columns in subtables");
226  flagInhAttrs(fout->dopt, tblinfo, numTables);
227 
228  pg_log_info("reading indexes");
229  getIndexes(fout, tblinfo, numTables);
230 
231  pg_log_info("flagging indexes in partitioned tables");
232  flagInhIndexes(fout, tblinfo, numTables);
233 
234  pg_log_info("reading extended statistics");
235  getExtendedStatistics(fout);
236 
237  pg_log_info("reading constraints");
238  getConstraints(fout, tblinfo, numTables);
239 
240  pg_log_info("reading triggers");
241  getTriggers(fout, tblinfo, numTables);
242 
243  pg_log_info("reading rewrite rules");
244  getRules(fout, &numRules);
245 
246  pg_log_info("reading policies");
247  getPolicies(fout, tblinfo, numTables);
248 
249  pg_log_info("reading publications");
250  getPublications(fout);
251 
252  pg_log_info("reading publication membership");
253  getPublicationTables(fout, tblinfo, numTables);
254 
255  pg_log_info("reading subscriptions");
256  getSubscriptions(fout);
257 
258  *numTablesPtr = numTables;
259  return tblinfo;
260 }
FuncInfo * getFuncs(Archive *fout, int *numFuncs)
Definition: pg_dump.c:5821
static DumpableObject ** collinfoindex
Definition: common.c:52
static int numTypes
Definition: common.c:56
AggInfo * getAggregates(Archive *fout, int *numAggs)
Definition: pg_dump.c:5628
void getPublicationTables(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:4048
CollInfo * getCollations(Archive *fout, int *numCollations)
Definition: pg_dump.c:5246
OprInfo * getOperators(Archive *fout, int *numOprs)
Definition: pg_dump.c:5164
static DumpableObject ** oprinfoindex
Definition: common.c:51
TransformInfo * getTransforms(Archive *fout, int *numTransforms)
Definition: pg_dump.c:8367
DefaultACLInfo * getDefaultACLs(Archive *fout, int *numDefaultACLs)
Definition: pg_dump.c:9523
static void flagInhTables(Archive *fout, TableInfo *tbinfo, int numTables, InhInfo *inhinfo, int numInherits)
Definition: common.c:273
static int numFuncs
Definition: common.c:57
AccessMethodInfo * getAccessMethods(Archive *fout, int *numAccessMethods)
Definition: pg_dump.c:5397
OpclassInfo * getOpclasses(Archive *fout, int *numOpclasses)
Definition: pg_dump.c:5471
TSConfigInfo * getTSConfigurations(Archive *fout, int *numTSConfigs)
Definition: pg_dump.c:9131
static int numTables
Definition: common.c:55
static DumpableObject ** buildIndexArray(void *objArray, int numObjs, Size objSize)
Definition: common.c:717
TSParserInfo * getTSParsers(Archive *fout, int *numTSParsers)
Definition: pg_dump.c:8883
static DumpableObject ** typinfoindex
Definition: common.c:49
void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7431
static void flagInhIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
InhInfo * getInherits(Archive *fout, int *numInherits)
Definition: pg_dump.c:6950
static int numOperators
Definition: common.c:58
DumpOptions * dopt
Definition: pg_backup.h:182
TableInfo * getTables(Archive *fout, int *numTables)
Definition: pg_dump.c:6055
void getPolicies(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:3575
EventTriggerInfo * getEventTriggers(Archive *fout, int *numEventTriggers)
Definition: pg_dump.c:7985
static DumpableObject ** tblinfoindex
Definition: common.c:48
NamespaceInfo * getNamespaces(Archive *fout, int *numNamespaces)
Definition: pg_dump.c:4685
static int numExtensions
Definition: common.c:61
static int numNamespaces
Definition: common.c:60
RuleInfo * getRules(Archive *fout, int *numRules)
Definition: pg_dump.c:7678
FdwInfo * getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
Definition: pg_dump.c:9207
void processExtensionTables(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:17821
void getSubscriptions(Archive *fout)
Definition: pg_dump.c:4196
void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:6999
TSDictInfo * getTSDictionaries(Archive *fout, int *numTSDicts)
Definition: pg_dump.c:8973
void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:7791
void getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
Definition: pg_dump.c:8464
void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables)
Definition: pg_dump.c:6887
ConvInfo * getConversions(Archive *fout, int *numConversions)
Definition: pg_dump.c:5325
OpfamilyInfo * getOpfamilies(Archive *fout, int *numOpfamilies)
Definition: pg_dump.c:5545
TSTemplateInfo * getTSTemplates(Archive *fout, int *numTSTemplates)
Definition: pg_dump.c:9056
static int numCollations
Definition: common.c:59
void getExtendedStatistics(Archive *fout)
Definition: pg_dump.c:7354
ExtensionInfo * getExtensions(Archive *fout, int *numExtensions)
Definition: pg_dump.c:4831
TypeInfo * getTypes(Archive *fout, int *numTypes)
Definition: pg_dump.c:4915
static DumpableObject ** extinfoindex
Definition: common.c:54
void getPublications(Archive *fout)
Definition: pg_dump.c:3850
ForeignServerInfo * getForeignServers(Archive *fout, int *numForeignServers)
Definition: pg_dump.c:9373
static DumpableObject ** funinfoindex
Definition: common.c:50
static DumpableObject ** nspinfoindex
Definition: common.c:53
ProcLangInfo * getProcLangs(Archive *fout, int *numProcLangs)
Definition: pg_dump.c:8076
void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], int numExtensions)
Definition: pg_dump.c:17716
static void flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables)
Definition: common.c:439
#define pg_log_info(...)
Definition: logging.h:88
CastInfo * getCasts(Archive *fout, int *numCasts)
Definition: pg_dump.c:8254

◆ parseOidArray()

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

Definition at line 1052 of file common.c.

References atooid, exit_nicely, InvalidOid, and pg_log_error.

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

1053 {
1054  int j,
1055  argNum;
1056  char temp[100];
1057  char s;
1058 
1059  argNum = 0;
1060  j = 0;
1061  for (;;)
1062  {
1063  s = *str++;
1064  if (s == ' ' || s == '\0')
1065  {
1066  if (j > 0)
1067  {
1068  if (argNum >= arraysize)
1069  {
1070  pg_log_error("could not parse numeric array \"%s\": too many numbers", str);
1071  exit_nicely(1);
1072  }
1073  temp[j] = '\0';
1074  array[argNum++] = atooid(temp);
1075  j = 0;
1076  }
1077  if (s == '\0')
1078  break;
1079  }
1080  else
1081  {
1082  if (!(isdigit((unsigned char) s) || s == '-') ||
1083  j >= sizeof(temp) - 1)
1084  {
1085  pg_log_error("could not parse numeric array \"%s\": invalid character in number", str);
1086  exit_nicely(1);
1087  }
1088  temp[j++] = s;
1089  }
1090  }
1091 
1092  while (argNum < arraysize)
1093  array[argNum++] = InvalidOid;
1094 }
#define pg_log_error(...)
Definition: logging.h:80
#define atooid(x)
Definition: postgres_ext.h:42
#define exit_nicely(code)
Definition: pg_dumpall.c:96
#define InvalidOid
Definition: postgres_ext.h:36

◆ removeObjectDependency()

void removeObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

◆ setExtensionMembership()

void setExtensionMembership ( ExtensionMemberId extmems,
int  nextmems 
)

Definition at line 921 of file common.c.

References ExtensionMemberIdCompare(), numextmembers, and qsort.

Referenced by getExtensionMembership().

922 {
923  /* Sort array in preparation for binary searches */
924  if (nextmems > 1)
925  qsort((void *) extmems, nextmems, sizeof(ExtensionMemberId),
927  /* And save */
928  extmembers = extmems;
929  numextmembers = nextmems;
930 }
static int ExtensionMemberIdCompare(const void *p1, const void *p2)
Definition: common.c:975
static ExtensionMemberId * extmembers
Definition: common.c:64
static int numextmembers
Definition: common.c:65
#define qsort(a, b, c, d)
Definition: port.h:475

◆ strInArray()

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

Definition at line 1105 of file common.c.

References i.

Referenced by flagInhAttrs().

1106 {
1107  int i;
1108 
1109  for (i = 0; i < arr_size; i++)
1110  {
1111  if (strcmp(pattern, arr[i]) == 0)
1112  return i;
1113  }
1114  return -1;
1115 }
int i

Variable Documentation

◆ allocedDumpIds

int allocedDumpIds = 0
static

Definition at line 30 of file common.c.

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

◆ catalogIdMap

DumpableObject** catalogIdMap = NULL
static

Definition at line 37 of file common.c.

Referenced by findObjectByCatalogId().

◆ catalogIdMapValid

bool catalogIdMapValid = false
static

Definition at line 36 of file common.c.

Referenced by AssignDumpId(), and findObjectByCatalogId().

◆ collinfoindex

DumpableObject** collinfoindex
static

Definition at line 52 of file common.c.

◆ dumpIdMap

DumpableObject** dumpIdMap = NULL
static

Definition at line 29 of file common.c.

◆ extinfoindex

DumpableObject** extinfoindex
static

Definition at line 54 of file common.c.

◆ extmembers

ExtensionMemberId* extmembers
static

Definition at line 64 of file common.c.

Referenced by findOwningExtension(), and getExtensionMembership().

◆ funinfoindex

DumpableObject** funinfoindex
static

Definition at line 50 of file common.c.

◆ lastDumpId

DumpId lastDumpId = 0
static

Definition at line 31 of file common.c.

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

◆ nspinfoindex

DumpableObject** nspinfoindex
static

Definition at line 53 of file common.c.

◆ numCatalogIds

int numCatalogIds = 0
static

Definition at line 38 of file common.c.

Referenced by findObjectByCatalogId().

◆ numCollations

int numCollations
static

Definition at line 59 of file common.c.

Referenced by findCollationByOid(), and getSchemaData().

◆ numExtensions

int numExtensions
static

Definition at line 61 of file common.c.

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

◆ numextmembers

int numextmembers
static

Definition at line 65 of file common.c.

Referenced by findOwningExtension(), and setExtensionMembership().

◆ numFuncs

int numFuncs
static

Definition at line 57 of file common.c.

Referenced by findFuncByOid(), and getSchemaData().

◆ numNamespaces

int numNamespaces
static

Definition at line 60 of file common.c.

Referenced by findNamespaceByOid(), and getSchemaData().

◆ numOperators

int numOperators
static

Definition at line 58 of file common.c.

Referenced by findOprByOid(), and getSchemaData().

◆ numTables

◆ numTypes

int numTypes
static

Definition at line 56 of file common.c.

Referenced by findTypeByOid(), and getSchemaData().

◆ oprinfoindex

DumpableObject** oprinfoindex
static

Definition at line 51 of file common.c.

◆ tblinfoindex

DumpableObject** tblinfoindex
static

Definition at line 48 of file common.c.

◆ typinfoindex

DumpableObject** typinfoindex
static

Definition at line 49 of file common.c.