PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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.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 (TableInfo *tbinfo, int numTables, InhInfo *inhinfo, int numInherits)
 
static void flagPartitions (TableInfo *tblinfo, int numTables, PartInfo *partinfo, int numPartitions)
 
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 void findPartitionParentByOid (TableInfo *self, PartInfo *partinfo, int numPartitions)
 
static int strInArray (const char *pattern, char **arr, int arr_size)
 
TableInfogetSchemaData (Archive *fout, int *numTablesPtr)
 
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

void addObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 749 of file common.c.

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

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

750 {
751  if (dobj->nDeps >= dobj->allocDeps)
752  {
753  if (dobj->allocDeps <= 0)
754  {
755  dobj->allocDeps = 16;
756  dobj->dependencies = (DumpId *)
757  pg_malloc(dobj->allocDeps * sizeof(DumpId));
758  }
759  else
760  {
761  dobj->allocDeps *= 2;
762  dobj->dependencies = (DumpId *)
763  pg_realloc(dobj->dependencies,
764  dobj->allocDeps * sizeof(DumpId));
765  }
766  }
767  dobj->dependencies[dobj->nDeps++] = refId;
768 }
int DumpId
Definition: pg_backup.h:229
DumpId * dependencies
Definition: pg_dump.h:138
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
void AssignDumpId ( DumpableObject dobj)

Definition at line 513 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, NULL, pg_malloc(), and pg_realloc().

Referenced by createBoundaryObjects(), flagInhAttrs(), 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().

514 {
515  dobj->dumpId = ++lastDumpId;
516  dobj->name = NULL; /* must be set later */
517  dobj->namespace = NULL; /* may be set later */
518  dobj->dump = DUMP_COMPONENT_ALL; /* default assumption */
519  dobj->ext_member = false; /* default assumption */
520  dobj->dependencies = NULL;
521  dobj->nDeps = 0;
522  dobj->allocDeps = 0;
523 
524  while (dobj->dumpId >= allocedDumpIds)
525  {
526  int newAlloc;
527 
528  if (allocedDumpIds <= 0)
529  {
530  newAlloc = 256;
532  pg_malloc(newAlloc * sizeof(DumpableObject *));
533  }
534  else
535  {
536  newAlloc = allocedDumpIds * 2;
538  pg_realloc(dumpIdMap, newAlloc * sizeof(DumpableObject *));
539  }
540  memset(dumpIdMap + allocedDumpIds, 0,
541  (newAlloc - allocedDumpIds) * sizeof(DumpableObject *));
542  allocedDumpIds = newAlloc;
543  }
544  dumpIdMap[dobj->dumpId] = dobj;
545 
546  /* mark catalogIdMap invalid, but don't rebuild it yet */
547  catalogIdMapValid = false;
548 }
char * name
Definition: pg_dump.h:133
static int allocedDumpIds
Definition: common.c:32
DumpComponents dump
Definition: pg_dump.h:134
static DumpId lastDumpId
Definition: common.c:33
static DumpableObject ** dumpIdMap
Definition: common.c:31
DumpId * dependencies
Definition: pg_dump.h:138
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
DumpId dumpId
Definition: pg_dump.h:132
bool ext_member
Definition: pg_dump.h:137
void * pg_realloc(void *ptr, size_t size)
Definition: fe_memutils.c:65
#define NULL
Definition: c.h:229
static bool catalogIdMapValid
Definition: common.c:38
#define DUMP_COMPONENT_ALL
Definition: pg_dump.h:99
static DumpableObject ** buildIndexArray ( void *  objArray,
int  numObjs,
Size  objSize 
)
static

Definition at line 684 of file common.c.

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

Referenced by getSchemaData().

685 {
686  DumpableObject **ptrs;
687  int i;
688 
689  ptrs = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
690  for (i = 0; i < numObjs; i++)
691  ptrs[i] = (DumpableObject *) ((char *) objArray + i * objSize);
692 
693  /* We can use DOCatalogIdCompare to sort since its first key is OID */
694  if (numObjs > 1)
695  qsort((void *) ptrs, numObjs, sizeof(DumpableObject *),
697 
698  return ptrs;
699 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:705
int i
#define qsort(a, b, c, d)
Definition: port.h:440
DumpId createDumpId ( void  )
static int DOCatalogIdCompare ( const void *  p1,
const void *  p2 
)
static

Definition at line 705 of file common.c.

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

Referenced by buildIndexArray(), and findObjectByCatalogId().

706 {
707  const DumpableObject *obj1 = *(DumpableObject *const *) p1;
708  const DumpableObject *obj2 = *(DumpableObject *const *) p2;
709  int cmpval;
710 
711  /*
712  * Compare OID first since it's usually unique, whereas there will only be
713  * a few distinct values of tableoid.
714  */
715  cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
716  if (cmpval == 0)
717  cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
718  return cmpval;
719 }
Oid tableoid
Definition: pg_backup.h:225
#define oidcmp(x, y)
Definition: pg_dump.h:20
CatalogId catId
Definition: pg_dump.h:131
static int ExtensionMemberIdCompare ( const void *  p1,
const void *  p2 
)
static

Definition at line 927 of file common.c.

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

Referenced by setExtensionMembership().

928 {
929  const ExtensionMemberId *obj1 = (const ExtensionMemberId *) p1;
930  const ExtensionMemberId *obj2 = (const ExtensionMemberId *) p2;
931  int cmpval;
932 
933  /*
934  * Compare OID first since it's usually unique, whereas there will only be
935  * a few distinct values of tableoid.
936  */
937  cmpval = oidcmp(obj1->catId.oid, obj2->catId.oid);
938  if (cmpval == 0)
939  cmpval = oidcmp(obj1->catId.tableoid, obj2->catId.tableoid);
940  return cmpval;
941 }
Oid tableoid
Definition: pg_backup.h:225
#define oidcmp(x, y)
Definition: pg_dump.h:20
CatalogId catId
Definition: pg_dump.h:626
CollInfo* findCollationByOid ( Oid  oid)

Definition at line 840 of file common.c.

References findObjectByOid(), and numCollations.

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

841 {
843 }
static DumpableObject ** collinfoindex
Definition: common.c:54
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static int numCollations
Definition: common.c:61
ExtensionInfo* findExtensionByOid ( Oid  oid)

Definition at line 862 of file common.c.

References findObjectByOid(), and numExtensions.

Referenced by getExtensionMembership().

863 {
865 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static int numExtensions
Definition: common.c:63
static DumpableObject ** extinfoindex
Definition: common.c:56
FuncInfo* findFuncByOid ( Oid  oid)

Definition at line 818 of file common.c.

References findObjectByOid(), and numFuncs.

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

819 {
820  return (FuncInfo *) findObjectByOid(oid, funinfoindex, numFuncs);
821 }
static int numFuncs
Definition: common.c:59
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static DumpableObject ** funinfoindex
Definition: common.c:52
NamespaceInfo* findNamespaceByOid ( Oid  oid)

Definition at line 851 of file common.c.

References findObjectByOid(), and numNamespaces.

Referenced by findNamespace().

852 {
854 }
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static int numNamespaces
Definition: common.c:62
static DumpableObject ** nspinfoindex
Definition: common.c:55
DumpableObject* findObjectByCatalogId ( CatalogId  catalogId)

Definition at line 595 of file common.c.

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

Referenced by buildMatViewRefreshDependencies(), and getDependencies().

596 {
597  DumpableObject **low;
598  DumpableObject **high;
599 
600  if (!catalogIdMapValid)
601  {
602  if (catalogIdMap)
605  if (numCatalogIds > 1)
606  qsort((void *) catalogIdMap, numCatalogIds,
608  catalogIdMapValid = true;
609  }
610 
611  /*
612  * We could use bsearch() here, but the notational cruft of calling
613  * bsearch is nearly as bad as doing it ourselves; and the generalized
614  * bsearch function is noticeably slower as well.
615  */
616  if (numCatalogIds <= 0)
617  return NULL;
618  low = catalogIdMap;
619  high = catalogIdMap + (numCatalogIds - 1);
620  while (low <= high)
621  {
622  DumpableObject **middle;
623  int difference;
624 
625  middle = low + (high - low) / 2;
626  /* comparison must match DOCatalogIdCompare, below */
627  difference = oidcmp((*middle)->catId.oid, catalogId.oid);
628  if (difference == 0)
629  difference = oidcmp((*middle)->catId.tableoid, catalogId.tableoid);
630  if (difference == 0)
631  return *middle;
632  else if (difference < 0)
633  low = middle + 1;
634  else
635  high = middle - 1;
636  }
637  return NULL;
638 }
Oid tableoid
Definition: pg_backup.h:225
#define oidcmp(x, y)
Definition: pg_dump.h:20
static int DOCatalogIdCompare(const void *p1, const void *p2)
Definition: common.c:705
static int numCatalogIds
Definition: common.c:40
Datum difference(PG_FUNCTION_ARGS)
#define free(a)
Definition: header.h:65
#define NULL
Definition: c.h:229
static DumpableObject ** catalogIdMap
Definition: common.c:39
static bool catalogIdMapValid
Definition: common.c:38
#define qsort(a, b, c, d)
Definition: port.h:440
void getDumpableObjects(DumpableObject ***objs, int *numObjs)
Definition: common.c:727
DumpableObject* findObjectByDumpId ( DumpId  dumpId)

Definition at line 577 of file common.c.

References allocedDumpIds, and NULL.

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

578 {
579  if (dumpId <= 0 || dumpId >= allocedDumpIds)
580  return NULL; /* out of range? */
581  return dumpIdMap[dumpId];
582 }
static int allocedDumpIds
Definition: common.c:32
static DumpableObject ** dumpIdMap
Definition: common.c:31
#define NULL
Definition: c.h:229
static DumpableObject* findObjectByOid ( Oid  oid,
DumpableObject **  indexArray,
int  numObjs 
)
static

Definition at line 646 of file common.c.

References difference(), NULL, and oidcmp.

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

647 {
648  DumpableObject **low;
649  DumpableObject **high;
650 
651  /*
652  * This is the same as findObjectByCatalogId except we assume we need not
653  * look at table OID because the objects are all the same type.
654  *
655  * We could use bsearch() here, but the notational cruft of calling
656  * bsearch is nearly as bad as doing it ourselves; and the generalized
657  * bsearch function is noticeably slower as well.
658  */
659  if (numObjs <= 0)
660  return NULL;
661  low = indexArray;
662  high = indexArray + (numObjs - 1);
663  while (low <= high)
664  {
665  DumpableObject **middle;
666  int difference;
667 
668  middle = low + (high - low) / 2;
669  difference = oidcmp((*middle)->catId.oid, oid);
670  if (difference == 0)
671  return *middle;
672  else if (difference < 0)
673  low = middle + 1;
674  else
675  high = middle - 1;
676  }
677  return NULL;
678 }
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
#define NULL
Definition: c.h:229
OprInfo* findOprByOid ( Oid  oid)

Definition at line 829 of file common.c.

References findObjectByOid(), and numOperators.

830 {
832 }
static DumpableObject ** oprinfoindex
Definition: common.c:53
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static int numOperators
Definition: common.c:60
ExtensionInfo* findOwningExtension ( CatalogId  catalogId)

Definition at line 889 of file common.c.

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

Referenced by checkExtensionMembership().

890 {
891  ExtensionMemberId *low;
892  ExtensionMemberId *high;
893 
894  /*
895  * We could use bsearch() here, but the notational cruft of calling
896  * bsearch is nearly as bad as doing it ourselves; and the generalized
897  * bsearch function is noticeably slower as well.
898  */
899  if (numextmembers <= 0)
900  return NULL;
901  low = extmembers;
902  high = extmembers + (numextmembers - 1);
903  while (low <= high)
904  {
905  ExtensionMemberId *middle;
906  int difference;
907 
908  middle = low + (high - low) / 2;
909  /* comparison must match ExtensionMemberIdCompare, below */
910  difference = oidcmp(middle->catId.oid, catalogId.oid);
911  if (difference == 0)
912  difference = oidcmp(middle->catId.tableoid, catalogId.tableoid);
913  if (difference == 0)
914  return middle->ext;
915  else if (difference < 0)
916  low = middle + 1;
917  else
918  high = middle - 1;
919  }
920  return NULL;
921 }
ExtensionInfo * ext
Definition: pg_dump.h:627
Oid tableoid
Definition: pg_backup.h:225
#define oidcmp(x, y)
Definition: pg_dump.h:20
Datum difference(PG_FUNCTION_ARGS)
static ExtensionMemberId * extmembers
Definition: common.c:66
#define NULL
Definition: c.h:229
static int numextmembers
Definition: common.c:67
CatalogId catId
Definition: pg_dump.h:626
static void findParentsByOid ( TableInfo self,
InhInfo inhinfo,
int  numInherits 
)
static

Definition at line 949 of file common.c.

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

Referenced by flagInhTables().

951 {
952  Oid oid = self->dobj.catId.oid;
953  int i,
954  j;
955  int numParents;
956 
957  numParents = 0;
958  for (i = 0; i < numInherits; i++)
959  {
960  if (inhinfo[i].inhrelid == oid)
961  numParents++;
962  }
963 
964  self->numParents = numParents;
965 
966  if (numParents > 0)
967  {
968  self->parents = (TableInfo **)
969  pg_malloc(sizeof(TableInfo *) * numParents);
970  j = 0;
971  for (i = 0; i < numInherits; i++)
972  {
973  if (inhinfo[i].inhrelid == oid)
974  {
975  TableInfo *parent;
976 
977  parent = findTableByOid(inhinfo[i].inhparent);
978  if (parent == NULL)
979  {
980  write_msg(NULL, "failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n",
981  inhinfo[i].inhparent,
982  self->dobj.name,
983  oid);
984  exit_nicely(1);
985  }
986  self->parents[j++] = parent;
987  }
988  }
989  }
990  else
991  self->parents = NULL;
992 }
char * name
Definition: pg_dump.h:133
TableInfo * findTableByOid(Oid oid)
Definition: common.c:796
struct _tableInfo ** parents
Definition: pg_dump.h:325
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:261
#define exit_nicely(code)
Definition: pg_dumpall.c:89
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
int i
static void findPartitionParentByOid ( TableInfo self,
PartInfo partinfo,
int  numPartitions 
)
static

Definition at line 999 of file common.c.

References exit_nicely, findTableByOid(), i, NULL, _partInfo::partdef, _tableInfo::partitiondef, and write_msg().

Referenced by flagPartitions().

1001 {
1002  Oid oid = self->dobj.catId.oid;
1003  int i;
1004 
1005  for (i = 0; i < numPartitions; i++)
1006  {
1007  if (partinfo[i].partrelid == oid)
1008  {
1009  TableInfo *parent;
1010 
1011  parent = findTableByOid(partinfo[i].partparent);
1012  if (parent == NULL)
1013  {
1014  write_msg(NULL, "failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n",
1015  partinfo[i].partparent,
1016  self->dobj.name,
1017  oid);
1018  exit_nicely(1);
1019  }
1020  self->partitionOf = parent;
1021 
1022  /* While we're at it, also save the partdef */
1023  self->partitiondef = partinfo[i].partdef;
1024  }
1025  }
1026 }
char * name
Definition: pg_dump.h:133
TableInfo * findTableByOid(Oid oid)
Definition: common.c:796
char * partdef
Definition: pg_dump.h:481
unsigned int Oid
Definition: postgres_ext.h:31
DumpableObject dobj
Definition: pg_dump.h:261
#define exit_nicely(code)
Definition: pg_dumpall.c:89
char * partitiondef
Definition: pg_dump.h:330
void write_msg(const char *modulename, const char *fmt,...)
#define NULL
Definition: c.h:229
int i
TableInfo* findTableByOid ( Oid  oid)

Definition at line 796 of file common.c.

References findObjectByOid(), and numTables.

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

797 {
799 }
static int numTables
Definition: common.c:57
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static DumpableObject ** tblinfoindex
Definition: common.c:50
TypeInfo* findTypeByOid ( Oid  oid)

Definition at line 807 of file common.c.

References findObjectByOid(), and numTypes.

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

808 {
809  return (TypeInfo *) findObjectByOid(oid, typinfoindex, numTypes);
810 }
static int numTypes
Definition: common.c:58
static DumpableObject * findObjectByOid(Oid oid, DumpableObject **indexArray, int numObjs)
Definition: common.c:646
static DumpableObject ** typinfoindex
Definition: common.c:51
static void flagInhAttrs ( DumpOptions dopt,
TableInfo tblinfo,
int  numTables 
)
static

Definition at line 407 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, NULL, _tableInfo::numatts, _tableInfo::numParents, numTables, _dumpableObject::objType, CatalogId::oid, _tableInfo::parents, pg_malloc(), pg_strdup(), _tableInfo::relkind, RELKIND_MATVIEW, RELKIND_SEQUENCE, RELKIND_VIEW, _attrDefInfo::separate, shouldPrintColumn(), strInArray(), and CatalogId::tableoid.

Referenced by getSchemaData().

408 {
409  int i,
410  j,
411  k;
412 
413  for (i = 0; i < numTables; i++)
414  {
415  TableInfo *tbinfo = &(tblinfo[i]);
416  int numParents;
417  TableInfo **parents;
418 
419  /* Some kinds never have parents */
420  if (tbinfo->relkind == RELKIND_SEQUENCE ||
421  tbinfo->relkind == RELKIND_VIEW ||
422  tbinfo->relkind == RELKIND_MATVIEW)
423  continue;
424 
425  /* Don't bother computing anything for non-target tables, either */
426  if (!tbinfo->dobj.dump)
427  continue;
428 
429  numParents = tbinfo->numParents;
430  parents = tbinfo->parents;
431 
432  if (numParents == 0)
433  continue; /* nothing to see here, move along */
434 
435  /* For each column, search for matching column names in parent(s) */
436  for (j = 0; j < tbinfo->numatts; j++)
437  {
438  bool foundNotNull; /* Attr was NOT NULL in a parent */
439  bool foundDefault; /* Found a default in a parent */
440 
441  /* no point in examining dropped columns */
442  if (tbinfo->attisdropped[j])
443  continue;
444 
445  foundNotNull = false;
446  foundDefault = false;
447  for (k = 0; k < numParents; k++)
448  {
449  TableInfo *parent = parents[k];
450  int inhAttrInd;
451 
452  inhAttrInd = strInArray(tbinfo->attnames[j],
453  parent->attnames,
454  parent->numatts);
455  if (inhAttrInd >= 0)
456  {
457  foundNotNull |= parent->notnull[inhAttrInd];
458  foundDefault |= (parent->attrdefs[inhAttrInd] != NULL);
459  }
460  }
461 
462  /* Remember if we found inherited NOT NULL */
463  tbinfo->inhNotNull[j] = foundNotNull;
464 
465  /* Manufacture a DEFAULT NULL clause if necessary */
466  if (foundDefault && tbinfo->attrdefs[j] == NULL)
467  {
468  AttrDefInfo *attrDef;
469 
470  attrDef = (AttrDefInfo *) pg_malloc(sizeof(AttrDefInfo));
471  attrDef->dobj.objType = DO_ATTRDEF;
472  attrDef->dobj.catId.tableoid = 0;
473  attrDef->dobj.catId.oid = 0;
474  AssignDumpId(&attrDef->dobj);
475  attrDef->dobj.name = pg_strdup(tbinfo->dobj.name);
476  attrDef->dobj.namespace = tbinfo->dobj.namespace;
477  attrDef->dobj.dump = tbinfo->dobj.dump;
478 
479  attrDef->adtable = tbinfo;
480  attrDef->adnum = j + 1;
481  attrDef->adef_expr = pg_strdup("NULL");
482 
483  /* Will column be dumped explicitly? */
484  if (shouldPrintColumn(dopt, tbinfo, j))
485  {
486  attrDef->separate = false;
487  /* No dependency needed: NULL cannot have dependencies */
488  }
489  else
490  {
491  /* column will be suppressed, print default separately */
492  attrDef->separate = true;
493  /* ensure it comes out after the table */
494  addObjectDependency(&attrDef->dobj,
495  tbinfo->dobj.dumpId);
496  }
497 
498  tbinfo->attrdefs[j] = attrDef;
499  }
500  }
501  }
502 }
char * name
Definition: pg_dump.h:133
struct _tableInfo ** parents
Definition: pg_dump.h:325
char relkind
Definition: pg_dump.h:267
DumpComponents dump
Definition: pg_dump.h:134
Oid tableoid
Definition: pg_backup.h:225
void AssignDumpId(DumpableObject *dobj)
Definition: common.c:513
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno)
Definition: pg_dump.c:8163
#define RELKIND_MATVIEW
Definition: pg_class.h:165
bool * inhNotNull
Definition: pg_dump.h:316
DumpId dumpId
Definition: pg_dump.h:132
static int numTables
Definition: common.c:57
char ** attnames
Definition: pg_dump.h:302
DumpableObject dobj
Definition: pg_dump.h:261
static int strInArray(const char *pattern, char **arr, int arr_size)
Definition: common.c:1091
bool separate
Definition: pg_dump.h:339
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
bool * attisdropped
Definition: pg_dump.h:308
TableInfo * adtable
Definition: pg_dump.h:336
int numatts
Definition: pg_dump.h:301
bool * notnull
Definition: pg_dump.h:315
DumpableObject dobj
Definition: pg_dump.h:335
#define NULL
Definition: c.h:229
struct _attrDefInfo ** attrdefs
Definition: pg_dump.h:317
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:749
CatalogId catId
Definition: pg_dump.h:131
#define RELKIND_VIEW
Definition: pg_class.h:164
int i
int numParents
Definition: pg_dump.h:324
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
DumpableObjectType objType
Definition: pg_dump.h:130
char * adef_expr
Definition: pg_dump.h:338
static void flagInhTables ( TableInfo tbinfo,
int  numTables,
InhInfo inhinfo,
int  numInherits 
)
static

Definition at line 326 of file common.c.

References findParentsByOid(), i, _tableInfo::numParents, numTables, _tableInfo::parents, RELKIND_MATVIEW, RELKIND_SEQUENCE, and RELKIND_VIEW.

Referenced by getSchemaData().

328 {
329  int i,
330  j;
331  int numParents;
332  TableInfo **parents;
333 
334  for (i = 0; i < numTables; i++)
335  {
336  /* Some kinds never have parents */
337  if (tblinfo[i].relkind == RELKIND_SEQUENCE ||
338  tblinfo[i].relkind == RELKIND_VIEW ||
339  tblinfo[i].relkind == RELKIND_MATVIEW)
340  continue;
341 
342  /* Don't bother computing anything for non-target tables, either */
343  if (!tblinfo[i].dobj.dump)
344  continue;
345 
346  /* Find all the immediate parent tables */
347  findParentsByOid(&tblinfo[i], inhinfo, numInherits);
348 
349  /* Mark the parents as interesting for getTableAttrs */
350  numParents = tblinfo[i].numParents;
351  parents = tblinfo[i].parents;
352  for (j = 0; j < numParents; j++)
353  parents[j]->interesting = true;
354  }
355 }
struct _tableInfo ** parents
Definition: pg_dump.h:325
#define RELKIND_MATVIEW
Definition: pg_class.h:165
static void findParentsByOid(TableInfo *self, InhInfo *inhinfo, int numInherits)
Definition: common.c:949
static int numTables
Definition: common.c:57
#define RELKIND_VIEW
Definition: pg_class.h:164
int i
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
static void flagPartitions ( TableInfo tblinfo,
int  numTables,
PartInfo partinfo,
int  numPartitions 
)
static

Definition at line 364 of file common.c.

References addObjectDependency(), _tableInfo::dobj, _dumpableObject::dumpId, findPartitionParentByOid(), i, _tableInfo::interesting, numTables, _tableInfo::partitionOf, RELKIND_MATVIEW, RELKIND_SEQUENCE, and RELKIND_VIEW.

Referenced by getSchemaData().

366 {
367  int i;
368 
369  for (i = 0; i < numTables; i++)
370  {
371  /* Some kinds are never partitions */
372  if (tblinfo[i].relkind == RELKIND_SEQUENCE ||
373  tblinfo[i].relkind == RELKIND_VIEW ||
374  tblinfo[i].relkind == RELKIND_MATVIEW)
375  continue;
376 
377  /* Don't bother computing anything for non-target tables, either */
378  if (!tblinfo[i].dobj.dump)
379  continue;
380 
381  /* Find the parent TableInfo and save */
382  findPartitionParentByOid(&tblinfo[i], partinfo, numPartitions);
383 
384  /* Mark the parent as interesting for getTableAttrs */
385  if (tblinfo[i].partitionOf)
386  {
387  tblinfo[i].partitionOf->interesting = true;
388  addObjectDependency(&tblinfo[i].dobj,
389  tblinfo[i].partitionOf->dobj.dumpId);
390  }
391  }
392 }
static void findPartitionParentByOid(TableInfo *self, PartInfo *partinfo, int numPartitions)
Definition: common.c:999
#define RELKIND_MATVIEW
Definition: pg_class.h:165
DumpId dumpId
Definition: pg_dump.h:132
static int numTables
Definition: common.c:57
DumpableObject dobj
Definition: pg_dump.h:261
struct _tableInfo * partitionOf
Definition: pg_dump.h:329
void addObjectDependency(DumpableObject *dobj, DumpId refId)
Definition: common.c:749
bool interesting
Definition: pg_dump.h:293
#define RELKIND_VIEW
Definition: pg_class.h:164
int i
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
void getDumpableObjects ( DumpableObject ***  objs,
int *  numObjs 
)

Definition at line 727 of file common.c.

References allocedDumpIds, i, and pg_malloc().

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

728 {
729  int i,
730  j;
731 
732  *objs = (DumpableObject **)
734  j = 0;
735  for (i = 1; i < allocedDumpIds; i++)
736  {
737  if (dumpIdMap[i])
738  (*objs)[j++] = dumpIdMap[i];
739  }
740  *numObjs = j;
741 }
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
DumpId getMaxDumpId ( void  )

Definition at line 566 of file common.c.

References lastDumpId.

Referenced by findDependencyLoops(), and TopoSort().

567 {
568  return lastDumpId;
569 }
static DumpId lastDumpId
Definition: common.c:33
TableInfo* getSchemaData ( Archive fout,
int *  numTablesPtr 
)

Definition at line 90 of file common.c.

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

Referenced by main().

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

Definition at line 1038 of file common.c.

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

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

1039 {
1040  int j,
1041  argNum;
1042  char temp[100];
1043  char s;
1044 
1045  argNum = 0;
1046  j = 0;
1047  for (;;)
1048  {
1049  s = *str++;
1050  if (s == ' ' || s == '\0')
1051  {
1052  if (j > 0)
1053  {
1054  if (argNum >= arraysize)
1055  {
1056  write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str);
1057  exit_nicely(1);
1058  }
1059  temp[j] = '\0';
1060  array[argNum++] = atooid(temp);
1061  j = 0;
1062  }
1063  if (s == '\0')
1064  break;
1065  }
1066  else
1067  {
1068  if (!(isdigit((unsigned char) s) || s == '-') ||
1069  j >= sizeof(temp) - 1)
1070  {
1071  write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str);
1072  exit_nicely(1);
1073  }
1074  temp[j++] = s;
1075  }
1076  }
1077 
1078  while (argNum < arraysize)
1079  array[argNum++] = InvalidOid;
1080 }
#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,...)
#define NULL
Definition: c.h:229
void removeObjectDependency ( DumpableObject dobj,
DumpId  refId 
)

Definition at line 776 of file common.c.

References _dumpableObject::dependencies, i, and _dumpableObject::nDeps.

Referenced by repairDependencyLoop(), repairDomainConstraintLoop(), repairDomainConstraintMultiLoop(), repairMatViewBoundaryMultiLoop(), repairTableAttrDefLoop(), repairTableAttrDefMultiLoop(), repairTableConstraintLoop(), repairTableConstraintMultiLoop(), repairTypeFuncLoop(), repairViewRuleLoop(), and repairViewRuleMultiLoop().

777 {
778  int i;
779  int j = 0;
780 
781  for (i = 0; i < dobj->nDeps; i++)
782  {
783  if (dobj->dependencies[i] != refId)
784  dobj->dependencies[j++] = dobj->dependencies[i];
785  }
786  dobj->nDeps = j;
787 }
DumpId * dependencies
Definition: pg_dump.h:138
int i
void setExtensionMembership ( ExtensionMemberId extmems,
int  nextmems 
)

Definition at line 873 of file common.c.

References ExtensionMemberIdCompare(), numextmembers, and qsort.

Referenced by getExtensionMembership().

874 {
875  /* Sort array in preparation for binary searches */
876  if (nextmems > 1)
877  qsort((void *) extmems, nextmems, sizeof(ExtensionMemberId),
879  /* And save */
880  extmembers = extmems;
881  numextmembers = nextmems;
882 }
static int ExtensionMemberIdCompare(const void *p1, const void *p2)
Definition: common.c:927
static ExtensionMemberId * extmembers
Definition: common.c:66
static int numextmembers
Definition: common.c:67
#define qsort(a, b, c, d)
Definition: port.h:440
static int strInArray ( const char *  pattern,
char **  arr,
int  arr_size 
)
static

Definition at line 1091 of file common.c.

References i.

Referenced by flagInhAttrs().

1092 {
1093  int i;
1094 
1095  for (i = 0; i < arr_size; i++)
1096  {
1097  if (strcmp(pattern, arr[i]) == 0)
1098  return i;
1099  }
1100  return -1;
1101 }
int i

Variable Documentation

int allocedDumpIds = 0
static

Definition at line 32 of file common.c.

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

DumpableObject** catalogIdMap = NULL
static

Definition at line 39 of file common.c.

Referenced by findObjectByCatalogId().

bool catalogIdMapValid = false
static

Definition at line 38 of file common.c.

Referenced by AssignDumpId(), and findObjectByCatalogId().

DumpableObject** collinfoindex
static

Definition at line 54 of file common.c.

DumpableObject** dumpIdMap = NULL
static

Definition at line 31 of file common.c.

DumpableObject** extinfoindex
static

Definition at line 56 of file common.c.

ExtensionMemberId* extmembers
static

Definition at line 66 of file common.c.

Referenced by findOwningExtension(), and getExtensionMembership().

DumpableObject** funinfoindex
static

Definition at line 52 of file common.c.

DumpId lastDumpId = 0
static

Definition at line 33 of file common.c.

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

DumpableObject** nspinfoindex
static

Definition at line 55 of file common.c.

int numCatalogIds = 0
static

Definition at line 40 of file common.c.

Referenced by findObjectByCatalogId().

int numCollations
static

Definition at line 61 of file common.c.

Referenced by findCollationByOid(), and getSchemaData().

int numExtensions
static

Definition at line 63 of file common.c.

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

int numextmembers
static

Definition at line 67 of file common.c.

Referenced by findOwningExtension(), and setExtensionMembership().

int numFuncs
static

Definition at line 59 of file common.c.

Referenced by findFuncByOid(), and getSchemaData().

int numNamespaces
static

Definition at line 62 of file common.c.

Referenced by findNamespaceByOid(), and getSchemaData().

int numOperators
static

Definition at line 60 of file common.c.

Referenced by findOprByOid(), and getSchemaData().

int numTypes
static

Definition at line 58 of file common.c.

Referenced by findTypeByOid(), and getSchemaData().

DumpableObject** oprinfoindex
static

Definition at line 53 of file common.c.

DumpableObject** tblinfoindex
static

Definition at line 50 of file common.c.

DumpableObject** typinfoindex
static

Definition at line 51 of file common.c.