PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dependency.h File Reference
Include dependency graph for dependency.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LAST_OCLASS   OCLASS_TRANSFORM
 
#define PERFORM_DELETION_INTERNAL   0x0001 /* internal action */
 
#define PERFORM_DELETION_CONCURRENTLY   0x0002 /* concurrent drop */
 
#define PERFORM_DELETION_QUIETLY   0x0004 /* suppress notices */
 
#define PERFORM_DELETION_SKIP_ORIGINAL   0x0008 /* keep original obj */
 
#define PERFORM_DELETION_SKIP_EXTENSIONS   0x0010 /* keep extensions */
 

Typedefs

typedef enum DependencyType DependencyType
 
typedef enum SharedDependencyType SharedDependencyType
 
typedef struct ObjectAddresses ObjectAddresses
 
typedef enum ObjectClass ObjectClass
 

Enumerations

enum  DependencyType {
  DEPENDENCY_NORMAL = 'n', DEPENDENCY_AUTO = 'a', DEPENDENCY_INTERNAL = 'i', DEPENDENCY_EXTENSION = 'e',
  DEPENDENCY_AUTO_EXTENSION = 'x', DEPENDENCY_PIN = 'p'
}
 
enum  SharedDependencyType {
  SHARED_DEPENDENCY_PIN = 'p', SHARED_DEPENDENCY_OWNER = 'o', SHARED_DEPENDENCY_ACL = 'a', SHARED_DEPENDENCY_POLICY = 'r',
  SHARED_DEPENDENCY_INVALID = 0
}
 
enum  ObjectClass {
  OCLASS_CLASS, OCLASS_PROC, OCLASS_TYPE, OCLASS_CAST,
  OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DEFAULT,
  OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPERATOR, OCLASS_OPCLASS,
  OCLASS_OPFAMILY, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC,
  OCLASS_REWRITE, OCLASS_TRIGGER, OCLASS_SCHEMA, OCLASS_TSPARSER,
  OCLASS_TSDICT, OCLASS_TSTEMPLATE, OCLASS_TSCONFIG, OCLASS_ROLE,
  OCLASS_DATABASE, OCLASS_TBLSPACE, OCLASS_FDW, OCLASS_FOREIGN_SERVER,
  OCLASS_USER_MAPPING, OCLASS_DEFACL, OCLASS_EXTENSION, OCLASS_EVENT_TRIGGER,
  OCLASS_POLICY, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_SUBSCRIPTION,
  OCLASS_TRANSFORM
}
 

Functions

void performDeletion (const ObjectAddress *object, DropBehavior behavior, int flags)
 
void performMultipleDeletions (const ObjectAddresses *objects, DropBehavior behavior, int flags)
 
void recordDependencyOnExpr (const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
 
void recordDependencyOnSingleRelExpr (const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool ignore_self)
 
ObjectClass getObjectClass (const ObjectAddress *object)
 
ObjectAddressesnew_object_addresses (void)
 
void add_exact_object_address (const ObjectAddress *object, ObjectAddresses *addrs)
 
bool object_address_present (const ObjectAddress *object, const ObjectAddresses *addrs)
 
void record_object_address_dependencies (const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
 
void free_object_addresses (ObjectAddresses *addrs)
 
void recordDependencyOn (const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
 
void recordMultipleDependencies (const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
 
void recordDependencyOnCurrentExtension (const ObjectAddress *object, bool isReplace)
 
long deleteDependencyRecordsFor (Oid classId, Oid objectId, bool skipExtensionDeps)
 
long deleteDependencyRecordsForClass (Oid classId, Oid objectId, Oid refclassId, char deptype)
 
long changeDependencyFor (Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
 
Oid getExtensionOfObject (Oid classId, Oid objectId)
 
bool sequenceIsOwned (Oid seqId, Oid *tableId, int32 *colId)
 
void markSequenceUnowned (Oid seqId)
 
ListgetOwnedSequences (Oid relid)
 
Oid get_constraint_index (Oid constraintId)
 
Oid get_index_constraint (Oid indexId)
 
void recordSharedDependencyOn (ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
 
void deleteSharedDependencyRecordsFor (Oid classId, Oid objectId, int32 objectSubId)
 
void recordDependencyOnOwner (Oid classId, Oid objectId, Oid owner)
 
void changeDependencyOnOwner (Oid classId, Oid objectId, Oid newOwnerId)
 
void updateAclDependencies (Oid classId, Oid objectId, int32 objectSubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
 
bool checkSharedDependencies (Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
 
void shdepLockAndCheckObject (Oid classId, Oid objectId)
 
void copyTemplateDependencies (Oid templateDbId, Oid newDbId)
 
void dropDatabaseDependencies (Oid databaseId)
 
void shdepDropOwned (List *relids, DropBehavior behavior)
 
void shdepReassignOwned (List *relids, Oid newrole)
 

Macro Definition Documentation

#define LAST_OCLASS   OCLASS_TRANSFORM

Definition at line 170 of file dependency.h.

Referenced by add_object_address().

#define PERFORM_DELETION_CONCURRENTLY   0x0002 /* concurrent drop */

Definition at line 174 of file dependency.h.

Referenced by AcquireDeletionLock(), deleteOneObject(), doDeletion(), and RemoveRelations().

#define PERFORM_DELETION_QUIETLY   0x0004 /* suppress notices */

Definition at line 175 of file dependency.h.

Referenced by do_autovacuum(), RemoveTempRelations(), and reportDependentObjects().

#define PERFORM_DELETION_SKIP_EXTENSIONS   0x0010 /* keep extensions */

Definition at line 177 of file dependency.h.

Referenced by do_autovacuum(), findDependentObjects(), and RemoveTempRelations().

#define PERFORM_DELETION_SKIP_ORIGINAL   0x0008 /* keep original obj */

Definition at line 176 of file dependency.h.

Referenced by deleteObjectsInList(), and RemoveTempRelations().

Typedef Documentation

Definition at line 123 of file dependency.h.

Enumeration Type Documentation

Enumerator
DEPENDENCY_NORMAL 
DEPENDENCY_AUTO 
DEPENDENCY_INTERNAL 
DEPENDENCY_EXTENSION 
DEPENDENCY_AUTO_EXTENSION 
DEPENDENCY_PIN 

Definition at line 73 of file dependency.h.

Enumerator
OCLASS_CLASS 
OCLASS_PROC 
OCLASS_TYPE 
OCLASS_CAST 
OCLASS_COLLATION 
OCLASS_CONSTRAINT 
OCLASS_CONVERSION 
OCLASS_DEFAULT 
OCLASS_LANGUAGE 
OCLASS_LARGEOBJECT 
OCLASS_OPERATOR 
OCLASS_OPCLASS 
OCLASS_OPFAMILY 
OCLASS_AM 
OCLASS_AMOP 
OCLASS_AMPROC 
OCLASS_REWRITE 
OCLASS_TRIGGER 
OCLASS_SCHEMA 
OCLASS_TSPARSER 
OCLASS_TSDICT 
OCLASS_TSTEMPLATE 
OCLASS_TSCONFIG 
OCLASS_ROLE 
OCLASS_DATABASE 
OCLASS_TBLSPACE 
OCLASS_FDW 
OCLASS_FOREIGN_SERVER 
OCLASS_USER_MAPPING 
OCLASS_DEFACL 
OCLASS_EXTENSION 
OCLASS_EVENT_TRIGGER 
OCLASS_POLICY 
OCLASS_PUBLICATION 
OCLASS_PUBLICATION_REL 
OCLASS_SUBSCRIPTION 
OCLASS_TRANSFORM 

Definition at line 129 of file dependency.h.

130 {
131  OCLASS_CLASS, /* pg_class */
132  OCLASS_PROC, /* pg_proc */
133  OCLASS_TYPE, /* pg_type */
134  OCLASS_CAST, /* pg_cast */
135  OCLASS_COLLATION, /* pg_collation */
136  OCLASS_CONSTRAINT, /* pg_constraint */
137  OCLASS_CONVERSION, /* pg_conversion */
138  OCLASS_DEFAULT, /* pg_attrdef */
139  OCLASS_LANGUAGE, /* pg_language */
140  OCLASS_LARGEOBJECT, /* pg_largeobject */
141  OCLASS_OPERATOR, /* pg_operator */
142  OCLASS_OPCLASS, /* pg_opclass */
143  OCLASS_OPFAMILY, /* pg_opfamily */
144  OCLASS_AM, /* pg_am */
145  OCLASS_AMOP, /* pg_amop */
146  OCLASS_AMPROC, /* pg_amproc */
147  OCLASS_REWRITE, /* pg_rewrite */
148  OCLASS_TRIGGER, /* pg_trigger */
149  OCLASS_SCHEMA, /* pg_namespace */
150  OCLASS_TSPARSER, /* pg_ts_parser */
151  OCLASS_TSDICT, /* pg_ts_dict */
152  OCLASS_TSTEMPLATE, /* pg_ts_template */
153  OCLASS_TSCONFIG, /* pg_ts_config */
154  OCLASS_ROLE, /* pg_authid */
155  OCLASS_DATABASE, /* pg_database */
156  OCLASS_TBLSPACE, /* pg_tablespace */
157  OCLASS_FDW, /* pg_foreign_data_wrapper */
158  OCLASS_FOREIGN_SERVER, /* pg_foreign_server */
159  OCLASS_USER_MAPPING, /* pg_user_mapping */
160  OCLASS_DEFACL, /* pg_default_acl */
161  OCLASS_EXTENSION, /* pg_extension */
162  OCLASS_EVENT_TRIGGER, /* pg_event_trigger */
163  OCLASS_POLICY, /* pg_policy */
164  OCLASS_PUBLICATION, /* pg_publication */
165  OCLASS_PUBLICATION_REL, /* pg_publication_rel */
166  OCLASS_SUBSCRIPTION, /* pg_subscription */
167  OCLASS_TRANSFORM /* pg_transform */
168 } ObjectClass;
ObjectClass
Definition: dependency.h:129
Enumerator
SHARED_DEPENDENCY_PIN 
SHARED_DEPENDENCY_OWNER 
SHARED_DEPENDENCY_ACL 
SHARED_DEPENDENCY_POLICY 
SHARED_DEPENDENCY_INVALID 

Definition at line 113 of file dependency.h.

Function Documentation

void add_exact_object_address ( const ObjectAddress object,
ObjectAddresses addrs 
)

Definition at line 2081 of file dependency.c.

References Assert, ObjectAddresses::extras, ObjectAddresses::maxrefs, ObjectAddresses::numrefs, ObjectAddressStack::object, ObjectAddresses::refs, and repalloc().

Referenced by AlterConstraintNamespaces(), AlterIndexNamespaces(), AlterRelationNamespaceInternal(), AlterTypeNamespaceInternal(), makeConfigurationDependencies(), recordDependencyOnSingleRelExpr(), RemoveObjects(), RemoveRelations(), and shdepDropOwned().

2083 {
2084  ObjectAddress *item;
2085 
2086  /* enlarge array if needed */
2087  if (addrs->numrefs >= addrs->maxrefs)
2088  {
2089  addrs->maxrefs *= 2;
2090  addrs->refs = (ObjectAddress *)
2091  repalloc(addrs->refs, addrs->maxrefs * sizeof(ObjectAddress));
2092  Assert(!addrs->extras);
2093  }
2094  /* record this item */
2095  item = addrs->refs + addrs->numrefs;
2096  *item = *object;
2097  addrs->numrefs++;
2098 }
ObjectAddress * refs
Definition: dependency.c:110
#define Assert(condition)
Definition: c.h:671
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1021
ObjectAddressExtra * extras
Definition: dependency.c:111
long changeDependencyFor ( Oid  classId,
Oid  objectId,
Oid  refClassId,
Oid  oldRefObjectId,
Oid  newRefObjectId 
)

Definition at line 295 of file pg_depend.c.

References Anum_pg_depend_classid, Anum_pg_depend_objid, BTEqualStrategyNumber, CatalogTupleDelete(), CatalogTupleUpdate(), ObjectAddress::classId, DependDependerIndexId, DependRelationId, ereport, errcode(), errmsg(), ERROR, getObjectDescription(), GETSTRUCT, heap_close, heap_copytuple(), heap_freetuple(), heap_open(), HeapTupleIsValid, isObjectPinned(), NULL, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by AlterExtensionNamespace(), AlterObjectNamespace_internal(), AlterRelationNamespaceInternal(), and AlterTypeNamespaceInternal().

298 {
299  long count = 0;
300  Relation depRel;
301  ScanKeyData key[2];
302  SysScanDesc scan;
303  HeapTuple tup;
304  ObjectAddress objAddr;
305  bool newIsPinned;
306 
308 
309  /*
310  * If oldRefObjectId is pinned, there won't be any dependency entries on
311  * it --- we can't cope in that case. (This isn't really worth expending
312  * code to fix, in current usage; it just means you can't rename stuff out
313  * of pg_catalog, which would likely be a bad move anyway.)
314  */
315  objAddr.classId = refClassId;
316  objAddr.objectId = oldRefObjectId;
317  objAddr.objectSubId = 0;
318 
319  if (isObjectPinned(&objAddr, depRel))
320  ereport(ERROR,
321  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
322  errmsg("cannot remove dependency on %s because it is a system object",
323  getObjectDescription(&objAddr))));
324 
325  /*
326  * We can handle adding a dependency on something pinned, though, since
327  * that just means deleting the dependency entry.
328  */
329  objAddr.objectId = newRefObjectId;
330 
331  newIsPinned = isObjectPinned(&objAddr, depRel);
332 
333  /* Now search for dependency records */
334  ScanKeyInit(&key[0],
336  BTEqualStrategyNumber, F_OIDEQ,
337  ObjectIdGetDatum(classId));
338  ScanKeyInit(&key[1],
340  BTEqualStrategyNumber, F_OIDEQ,
341  ObjectIdGetDatum(objectId));
342 
343  scan = systable_beginscan(depRel, DependDependerIndexId, true,
344  NULL, 2, key);
345 
346  while (HeapTupleIsValid((tup = systable_getnext(scan))))
347  {
348  Form_pg_depend depform = (Form_pg_depend) GETSTRUCT(tup);
349 
350  if (depform->refclassid == refClassId &&
351  depform->refobjid == oldRefObjectId)
352  {
353  if (newIsPinned)
354  CatalogTupleDelete(depRel, &tup->t_self);
355  else
356  {
357  /* make a modifiable copy */
358  tup = heap_copytuple(tup);
359  depform = (Form_pg_depend) GETSTRUCT(tup);
360 
361  depform->refobjid = newRefObjectId;
362 
363  CatalogTupleUpdate(depRel, &tup->t_self, tup);
364 
365  heap_freetuple(tup);
366  }
367 
368  count++;
369  }
370  }
371 
372  systable_endscan(scan);
373 
374  heap_close(depRel, RowExclusiveLock);
375 
376  return count;
377 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DependDependerIndexId
Definition: indexing.h:145
#define DependRelationId
Definition: pg_depend.h:29
int errcode(int sqlerrcode)
Definition: elog.c:575
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1374
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
char * getObjectDescription(const ObjectAddress *object)
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
static bool isObjectPinned(const ObjectAddress *object, Relation rel)
Definition: pg_depend.c:389
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
#define ereport(elevel, rest)
Definition: elog.h:122
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:210
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void changeDependencyOnOwner ( Oid  classId,
Oid  objectId,
Oid  newOwnerId 
)

Definition at line 303 of file pg_shdepend.c.

References AuthIdRelationId, heap_close, heap_open(), RowExclusiveLock, SHARED_DEPENDENCY_ACL, SHARED_DEPENDENCY_OWNER, SharedDependRelationId, shdepChangeDep(), and shdepDropDependency().

Referenced by AlterDatabaseOwner(), AlterEventTriggerOwner_internal(), AlterForeignDataWrapperOwner_internal(), AlterForeignServerOwner_internal(), AlterObjectOwner_internal(), AlterPublicationOwner_internal(), AlterSchemaOwner_internal(), AlterSubscriptionOwner_internal(), AlterTypeOwner_oid(), and ATExecChangeOwner().

304 {
305  Relation sdepRel;
306 
308 
309  /* Adjust the SHARED_DEPENDENCY_OWNER entry */
310  shdepChangeDep(sdepRel,
311  classId, objectId, 0,
312  AuthIdRelationId, newOwnerId,
314 
315  /*----------
316  * There should never be a SHARED_DEPENDENCY_ACL entry for the owner,
317  * so get rid of it if there is one. This can happen if the new owner
318  * was previously granted some rights to the object.
319  *
320  * This step is analogous to aclnewowner's removal of duplicate entries
321  * in the ACL. We have to do it to handle this scenario:
322  * A grants some rights on an object to B
323  * ALTER OWNER changes the object's owner to B
324  * ALTER OWNER changes the object's owner to C
325  * The third step would remove all mention of B from the object's ACL,
326  * but we'd still have a SHARED_DEPENDENCY_ACL for B if we did not do
327  * things this way.
328  *
329  * The rule against having a SHARED_DEPENDENCY_ACL entry for the owner
330  * allows us to fix things up in just this one place, without having
331  * to make the various ALTER OWNER routines each know about it.
332  *----------
333  */
334  shdepDropDependency(sdepRel, classId, objectId, 0, true,
335  AuthIdRelationId, newOwnerId,
337 
338  heap_close(sdepRel, RowExclusiveLock);
339 }
#define SharedDependRelationId
Definition: pg_shdepend.h:29
static void shdepChangeDep(Relation sdepRel, Oid classid, Oid objid, int32 objsubid, Oid refclassid, Oid refobjid, SharedDependencyType deptype)
Definition: pg_shdepend.c:193
#define heap_close(r, l)
Definition: heapam.h:97
#define AuthIdRelationId
Definition: pg_authid.h:42
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
static void shdepDropDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, bool drop_subobjects, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
Definition: pg_shdepend.c:899
bool checkSharedDependencies ( Oid  classId,
Oid  objectId,
char **  detail_msg,
char **  detail_log_msg 
)

Definition at line 521 of file pg_shdepend.c.

References AccessShareLock, Anum_pg_shdepend_refclassid, Anum_pg_shdepend_refobjid, appendStringInfo(), BTEqualStrategyNumber, remoteDep::count, StringInfoData::data, DatabaseRelationId, remoteDep::dbOid, ereport, errcode(), errmsg(), ERROR, getObjectDescription(), GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, initStringInfo(), InvalidOid, lappend(), StringInfoData::len, lfirst, list_free_deep(), LOCAL_OBJECT, MAX_REPORTED_DEPS, MyDatabaseId, ngettext, NIL, NULL, ObjectIdGetDatum, palloc(), pfree(), REMOTE_OBJECT, ScanKeyInit(), SHARED_DEPENDENCY_INVALID, SHARED_DEPENDENCY_PIN, SHARED_OBJECT, SharedDependReferenceIndexId, SharedDependRelationId, storeObjectDescription(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by DropRole().

523 {
524  Relation sdepRel;
525  ScanKeyData key[2];
526  SysScanDesc scan;
527  HeapTuple tup;
528  int numReportedDeps = 0;
529  int numNotReportedDeps = 0;
530  int numNotReportedDbs = 0;
531  List *remDeps = NIL;
532  ListCell *cell;
533  ObjectAddress object;
534  StringInfoData descs;
535  StringInfoData alldescs;
536 
537  /*
538  * We limit the number of dependencies reported to the client to
539  * MAX_REPORTED_DEPS, since client software may not deal well with
540  * enormous error strings. The server log always gets a full report.
541  */
542 #define MAX_REPORTED_DEPS 100
543 
544  initStringInfo(&descs);
545  initStringInfo(&alldescs);
546 
548 
549  ScanKeyInit(&key[0],
551  BTEqualStrategyNumber, F_OIDEQ,
552  ObjectIdGetDatum(classId));
553  ScanKeyInit(&key[1],
555  BTEqualStrategyNumber, F_OIDEQ,
556  ObjectIdGetDatum(objectId));
557 
558  scan = systable_beginscan(sdepRel, SharedDependReferenceIndexId, true,
559  NULL, 2, key);
560 
561  while (HeapTupleIsValid(tup = systable_getnext(scan)))
562  {
563  Form_pg_shdepend sdepForm = (Form_pg_shdepend) GETSTRUCT(tup);
564 
565  /* This case can be dispatched quickly */
566  if (sdepForm->deptype == SHARED_DEPENDENCY_PIN)
567  {
568  object.classId = classId;
569  object.objectId = objectId;
570  object.objectSubId = 0;
571  ereport(ERROR,
572  (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
573  errmsg("cannot drop %s because it is required by the database system",
574  getObjectDescription(&object))));
575  }
576 
577  object.classId = sdepForm->classid;
578  object.objectId = sdepForm->objid;
579  object.objectSubId = sdepForm->objsubid;
580 
581  /*
582  * If it's a dependency local to this database or it's a shared
583  * object, describe it.
584  *
585  * If it's a remote dependency, keep track of it so we can report the
586  * number of them later.
587  */
588  if (sdepForm->dbid == MyDatabaseId)
589  {
590  if (numReportedDeps < MAX_REPORTED_DEPS)
591  {
592  numReportedDeps++;
593  storeObjectDescription(&descs, LOCAL_OBJECT, &object,
594  sdepForm->deptype, 0);
595  }
596  else
597  numNotReportedDeps++;
598  storeObjectDescription(&alldescs, LOCAL_OBJECT, &object,
599  sdepForm->deptype, 0);
600  }
601  else if (sdepForm->dbid == InvalidOid)
602  {
603  if (numReportedDeps < MAX_REPORTED_DEPS)
604  {
605  numReportedDeps++;
606  storeObjectDescription(&descs, SHARED_OBJECT, &object,
607  sdepForm->deptype, 0);
608  }
609  else
610  numNotReportedDeps++;
611  storeObjectDescription(&alldescs, SHARED_OBJECT, &object,
612  sdepForm->deptype, 0);
613  }
614  else
615  {
616  /* It's not local nor shared, so it must be remote. */
617  remoteDep *dep;
618  bool stored = false;
619 
620  /*
621  * XXX this info is kept on a simple List. Maybe it's not good
622  * for performance, but using a hash table seems needlessly
623  * complex. The expected number of databases is not high anyway,
624  * I suppose.
625  */
626  foreach(cell, remDeps)
627  {
628  dep = lfirst(cell);
629  if (dep->dbOid == sdepForm->dbid)
630  {
631  dep->count++;
632  stored = true;
633  break;
634  }
635  }
636  if (!stored)
637  {
638  dep = (remoteDep *) palloc(sizeof(remoteDep));
639  dep->dbOid = sdepForm->dbid;
640  dep->count = 1;
641  remDeps = lappend(remDeps, dep);
642  }
643  }
644  }
645 
646  systable_endscan(scan);
647 
648  heap_close(sdepRel, AccessShareLock);
649 
650  /*
651  * Summarize dependencies in remote databases.
652  */
653  foreach(cell, remDeps)
654  {
655  remoteDep *dep = lfirst(cell);
656 
657  object.classId = DatabaseRelationId;
658  object.objectId = dep->dbOid;
659  object.objectSubId = 0;
660 
661  if (numReportedDeps < MAX_REPORTED_DEPS)
662  {
663  numReportedDeps++;
664  storeObjectDescription(&descs, REMOTE_OBJECT, &object,
666  }
667  else
668  numNotReportedDbs++;
669  storeObjectDescription(&alldescs, REMOTE_OBJECT, &object,
671  }
672 
673  list_free_deep(remDeps);
674 
675  if (descs.len == 0)
676  {
677  pfree(descs.data);
678  pfree(alldescs.data);
679  *detail_msg = *detail_log_msg = NULL;
680  return false;
681  }
682 
683  if (numNotReportedDeps > 0)
684  appendStringInfo(&descs, ngettext("\nand %d other object "
685  "(see server log for list)",
686  "\nand %d other objects "
687  "(see server log for list)",
688  numNotReportedDeps),
689  numNotReportedDeps);
690  if (numNotReportedDbs > 0)
691  appendStringInfo(&descs, ngettext("\nand objects in %d other database "
692  "(see server log for list)",
693  "\nand objects in %d other databases "
694  "(see server log for list)",
695  numNotReportedDbs),
696  numNotReportedDbs);
697 
698  *detail_msg = descs.data;
699  *detail_log_msg = alldescs.data;
700  return true;
701 }
#define NIL
Definition: pg_list.h:69
#define Anum_pg_shdepend_refclassid
Definition: pg_shdepend.h:75
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define SharedDependRelationId
Definition: pg_shdepend.h:29
FormData_pg_shdepend * Form_pg_shdepend
Definition: pg_shdepend.h:64
#define DatabaseRelationId
Definition: pg_database.h:29
#define AccessShareLock
Definition: lockdefs.h:36
#define MAX_REPORTED_DEPS
static void storeObjectDescription(StringInfo descs, SharedDependencyObjectType type, ObjectAddress *object, SharedDependencyType deptype, int count)
Definition: pg_shdepend.c:1059
int errcode(int sqlerrcode)
Definition: elog.c:575
#define heap_close(r, l)
Definition: heapam.h:97
void list_free_deep(List *list)
Definition: list.c:1147
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
char * getObjectDescription(const ObjectAddress *object)
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
void pfree(void *pointer)
Definition: mcxt.c:992
#define Anum_pg_shdepend_refobjid
Definition: pg_shdepend.h:76
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
List * lappend(List *list, void *datum)
Definition: list.c:128
void initStringInfo(StringInfo str)
Definition: stringinfo.c:65
#define ngettext(s, p, n)
Definition: c.h:127
Oid MyDatabaseId
Definition: globals.c:76
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
void * palloc(Size size)
Definition: mcxt.c:891
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define SharedDependReferenceIndexId
Definition: indexing.h:224
Definition: pg_list.h:45
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void copyTemplateDependencies ( Oid  templateDbId,
Oid  newDbId 
)

Definition at line 710 of file pg_shdepend.c.

References Anum_pg_shdepend_dbid, BTEqualStrategyNumber, CatalogCloseIndexes(), CatalogOpenIndexes(), CatalogTupleInsertWithInfo(), heap_close, heap_freetuple(), heap_modify_tuple(), heap_open(), HeapTupleIsValid, Natts_pg_shdepend, NULL, ObjectIdGetDatum, RelationGetDescr, RowExclusiveLock, ScanKeyInit(), SharedDependDependerIndexId, SharedDependRelationId, systable_beginscan(), systable_endscan(), systable_getnext(), and values.

Referenced by createdb().

711 {
712  Relation sdepRel;
713  TupleDesc sdepDesc;
714  ScanKeyData key[1];
715  SysScanDesc scan;
716  HeapTuple tup;
717  CatalogIndexState indstate;
719  bool nulls[Natts_pg_shdepend];
720  bool replace[Natts_pg_shdepend];
721 
723  sdepDesc = RelationGetDescr(sdepRel);
724 
725  indstate = CatalogOpenIndexes(sdepRel);
726 
727  /* Scan all entries with dbid = templateDbId */
728  ScanKeyInit(&key[0],
730  BTEqualStrategyNumber, F_OIDEQ,
731  ObjectIdGetDatum(templateDbId));
732 
733  scan = systable_beginscan(sdepRel, SharedDependDependerIndexId, true,
734  NULL, 1, key);
735 
736  /* Set up to copy the tuples except for inserting newDbId */
737  memset(values, 0, sizeof(values));
738  memset(nulls, false, sizeof(nulls));
739  memset(replace, false, sizeof(replace));
740 
741  replace[Anum_pg_shdepend_dbid - 1] = true;
742  values[Anum_pg_shdepend_dbid - 1] = ObjectIdGetDatum(newDbId);
743 
744  /*
745  * Copy the entries of the original database, changing the database Id to
746  * that of the new database. Note that because we are not copying rows
747  * with dbId == 0 (ie, rows describing dependent shared objects) we won't
748  * copy the ownership dependency of the template database itself; this is
749  * what we want.
750  */
751  while (HeapTupleIsValid(tup = systable_getnext(scan)))
752  {
753  HeapTuple newtup;
754 
755  newtup = heap_modify_tuple(tup, sdepDesc, values, nulls, replace);
756  CatalogTupleInsertWithInfo(sdepRel, newtup, indstate);
757 
758  heap_freetuple(newtup);
759  }
760 
761  systable_endscan(scan);
762 
763  CatalogCloseIndexes(indstate);
764  heap_close(sdepRel, RowExclusiveLock);
765 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define SharedDependDependerIndexId
Definition: indexing.h:222
#define SharedDependRelationId
Definition: pg_shdepend.h:29
#define RelationGetDescr(relation)
Definition: rel.h:425
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1374
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define RowExclusiveLock
Definition: lockdefs.h:38
#define Anum_pg_shdepend_dbid
Definition: pg_shdepend.h:71
uintptr_t Datum
Definition: postgres.h:374
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Definition: indexing.c:40
static Datum values[MAXATTR]
Definition: bootstrap.c:162
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:58
Oid CatalogTupleInsertWithInfo(Relation heapRel, HeapTuple tup, CatalogIndexState indstate)
Definition: indexing.c:186
#define Natts_pg_shdepend
Definition: pg_shdepend.h:70
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:793
#define BTEqualStrategyNumber
Definition: stratnum.h:31
long deleteDependencyRecordsFor ( Oid  classId,
Oid  objectId,
bool  skipExtensionDeps 
)

Definition at line 191 of file pg_depend.c.

References Anum_pg_depend_classid, Anum_pg_depend_objid, BTEqualStrategyNumber, CatalogTupleDelete(), DependDependerIndexId, DEPENDENCY_EXTENSION, DependRelationId, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, NULL, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by AlterPolicy(), create_proc_lang(), CreateTransform(), DefineQueryRewrite(), GenerateTypeDependencies(), InsertRule(), makeConfigurationDependencies(), makeOperatorDependencies(), ProcedureCreate(), RemoveRoleFromObjectPolicy(), and swap_relation_files().

193 {
194  long count = 0;
195  Relation depRel;
196  ScanKeyData key[2];
197  SysScanDesc scan;
198  HeapTuple tup;
199 
201 
202  ScanKeyInit(&key[0],
204  BTEqualStrategyNumber, F_OIDEQ,
205  ObjectIdGetDatum(classId));
206  ScanKeyInit(&key[1],
208  BTEqualStrategyNumber, F_OIDEQ,
209  ObjectIdGetDatum(objectId));
210 
211  scan = systable_beginscan(depRel, DependDependerIndexId, true,
212  NULL, 2, key);
213 
214  while (HeapTupleIsValid(tup = systable_getnext(scan)))
215  {
216  if (skipExtensionDeps &&
217  ((Form_pg_depend) GETSTRUCT(tup))->deptype == DEPENDENCY_EXTENSION)
218  continue;
219 
220  CatalogTupleDelete(depRel, &tup->t_self);
221  count++;
222  }
223 
224  systable_endscan(scan);
225 
226  heap_close(depRel, RowExclusiveLock);
227 
228  return count;
229 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DependDependerIndexId
Definition: indexing.h:145
#define DependRelationId
Definition: pg_depend.h:29
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
#define BTEqualStrategyNumber
Definition: stratnum.h:31
long deleteDependencyRecordsForClass ( Oid  classId,
Oid  objectId,
Oid  refclassId,
char  deptype 
)

Definition at line 241 of file pg_depend.c.

References Anum_pg_depend_classid, Anum_pg_depend_objid, BTEqualStrategyNumber, CatalogTupleDelete(), DependDependerIndexId, DependRelationId, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, NULL, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by AlterForeignDataWrapper(), ApplyExtensionUpdates(), ExecAlterExtensionContentsStmt(), index_constraint_create(), and markSequenceUnowned().

243 {
244  long count = 0;
245  Relation depRel;
246  ScanKeyData key[2];
247  SysScanDesc scan;
248  HeapTuple tup;
249 
251 
252  ScanKeyInit(&key[0],
254  BTEqualStrategyNumber, F_OIDEQ,
255  ObjectIdGetDatum(classId));
256  ScanKeyInit(&key[1],
258  BTEqualStrategyNumber, F_OIDEQ,
259  ObjectIdGetDatum(objectId));
260 
261  scan = systable_beginscan(depRel, DependDependerIndexId, true,
262  NULL, 2, key);
263 
264  while (HeapTupleIsValid(tup = systable_getnext(scan)))
265  {
266  Form_pg_depend depform = (Form_pg_depend) GETSTRUCT(tup);
267 
268  if (depform->refclassid == refclassId && depform->deptype == deptype)
269  {
270  CatalogTupleDelete(depRel, &tup->t_self);
271  count++;
272  }
273  }
274 
275  systable_endscan(scan);
276 
277  heap_close(depRel, RowExclusiveLock);
278 
279  return count;
280 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DependDependerIndexId
Definition: indexing.h:145
#define DependRelationId
Definition: pg_depend.h:29
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void deleteSharedDependencyRecordsFor ( Oid  classId,
Oid  objectId,
int32  objectSubId 
)

Definition at line 822 of file pg_shdepend.c.

References heap_close, heap_open(), InvalidOid, RowExclusiveLock, SHARED_DEPENDENCY_INVALID, SharedDependRelationId, and shdepDropDependency().

Referenced by AlterPolicy(), deleteOneObject(), DropSubscription(), DropTableSpace(), GenerateTypeDependencies(), makeConfigurationDependencies(), makeOperatorDependencies(), and RemoveRoleFromObjectPolicy().

823 {
824  Relation sdepRel;
825 
827 
828  shdepDropDependency(sdepRel, classId, objectId, objectSubId,
829  (objectSubId == 0),
832 
833  heap_close(sdepRel, RowExclusiveLock);
834 }
#define SharedDependRelationId
Definition: pg_shdepend.h:29
#define heap_close(r, l)
Definition: heapam.h:97
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
static void shdepDropDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, bool drop_subobjects, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
Definition: pg_shdepend.c:899
void dropDatabaseDependencies ( Oid  databaseId)

Definition at line 774 of file pg_shdepend.c.

References Anum_pg_shdepend_dbid, BTEqualStrategyNumber, CatalogTupleDelete(), DatabaseRelationId, heap_close, heap_open(), HeapTupleIsValid, InvalidOid, NULL, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), SHARED_DEPENDENCY_INVALID, SharedDependDependerIndexId, SharedDependRelationId, shdepDropDependency(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by dropdb().

775 {
776  Relation sdepRel;
777  ScanKeyData key[1];
778  SysScanDesc scan;
779  HeapTuple tup;
780 
782 
783  /*
784  * First, delete all the entries that have the database Oid in the dbid
785  * field.
786  */
787  ScanKeyInit(&key[0],
789  BTEqualStrategyNumber, F_OIDEQ,
790  ObjectIdGetDatum(databaseId));
791  /* We leave the other index fields unspecified */
792 
793  scan = systable_beginscan(sdepRel, SharedDependDependerIndexId, true,
794  NULL, 1, key);
795 
796  while (HeapTupleIsValid(tup = systable_getnext(scan)))
797  {
798  CatalogTupleDelete(sdepRel, &tup->t_self);
799  }
800 
801  systable_endscan(scan);
802 
803  /* Now delete all entries corresponding to the database itself */
804  shdepDropDependency(sdepRel, DatabaseRelationId, databaseId, 0, true,
807 
808  heap_close(sdepRel, RowExclusiveLock);
809 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define SharedDependDependerIndexId
Definition: indexing.h:222
#define SharedDependRelationId
Definition: pg_shdepend.h:29
#define DatabaseRelationId
Definition: pg_database.h:29
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:255
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define Anum_pg_shdepend_dbid
Definition: pg_shdepend.h:71
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
static void shdepDropDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, bool drop_subobjects, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
Definition: pg_shdepend.c:899
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void free_object_addresses ( ObjectAddresses addrs)

Definition at line 2297 of file dependency.c.

References ObjectAddresses::extras, pfree(), and ObjectAddresses::refs.

Referenced by AlterTableNamespace(), AlterTypeNamespace(), makeConfigurationDependencies(), performDeletion(), performMultipleDeletions(), recordDependencyOnExpr(), recordDependencyOnSingleRelExpr(), RemoveObjects(), RemoveRelations(), and shdepDropOwned().

2298 {
2299  pfree(addrs->refs);
2300  if (addrs->extras)
2301  pfree(addrs->extras);
2302  pfree(addrs);
2303 }
void pfree(void *pointer)
Definition: mcxt.c:992
ObjectAddress * refs
Definition: dependency.c:110
ObjectAddressExtra * extras
Definition: dependency.c:111
Oid get_constraint_index ( Oid  constraintId)

Definition at line 618 of file pg_depend.c.

References AccessShareLock, Anum_pg_depend_refclassid, Anum_pg_depend_refobjid, Anum_pg_depend_refobjsubid, BTEqualStrategyNumber, ConstraintRelationId, DEPENDENCY_INTERNAL, DependReferenceIndexId, DependRelationId, get_rel_relkind(), GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, Int32GetDatum, InvalidOid, NULL, ObjectIdGetDatum, RelationRelationId, RELKIND_INDEX, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by ATPostAlterTypeParse(), infer_arbiter_indexes(), and pg_get_constraintdef_worker().

619 {
620  Oid indexId = InvalidOid;
621  Relation depRel;
622  ScanKeyData key[3];
623  SysScanDesc scan;
624  HeapTuple tup;
625 
626  /* Search the dependency table for the dependent index */
628 
629  ScanKeyInit(&key[0],
631  BTEqualStrategyNumber, F_OIDEQ,
633  ScanKeyInit(&key[1],
635  BTEqualStrategyNumber, F_OIDEQ,
636  ObjectIdGetDatum(constraintId));
637  ScanKeyInit(&key[2],
639  BTEqualStrategyNumber, F_INT4EQ,
640  Int32GetDatum(0));
641 
642  scan = systable_beginscan(depRel, DependReferenceIndexId, true,
643  NULL, 3, key);
644 
645  while (HeapTupleIsValid(tup = systable_getnext(scan)))
646  {
647  Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
648 
649  /*
650  * We assume any internal dependency of an index on the constraint
651  * must be what we are looking for. (The relkind test is just
652  * paranoia; there shouldn't be any such dependencies otherwise.)
653  */
654  if (deprec->classid == RelationRelationId &&
655  deprec->objsubid == 0 &&
656  deprec->deptype == DEPENDENCY_INTERNAL &&
657  get_rel_relkind(deprec->objid) == RELKIND_INDEX)
658  {
659  indexId = deprec->objid;
660  break;
661  }
662  }
663 
664  systable_endscan(scan);
665  heap_close(depRel, AccessShareLock);
666 
667  return indexId;
668 }
#define Anum_pg_depend_refobjid
Definition: pg_depend.h:72
#define Anum_pg_depend_refobjsubid
Definition: pg_depend.h:73
#define Anum_pg_depend_refclassid
Definition: pg_depend.h:71
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1769
#define RelationRelationId
Definition: pg_class.h:29
#define DependReferenceIndexId
Definition: indexing.h:147
#define DependRelationId
Definition: pg_depend.h:29
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define Int32GetDatum(X)
Definition: postgres.h:487
#define RELKIND_INDEX
Definition: pg_class.h:161
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define ConstraintRelationId
Definition: pg_constraint.h:29
#define BTEqualStrategyNumber
Definition: stratnum.h:31
Oid get_index_constraint ( Oid  indexId)

Definition at line 676 of file pg_depend.c.

References AccessShareLock, Anum_pg_depend_classid, Anum_pg_depend_objid, Anum_pg_depend_objsubid, BTEqualStrategyNumber, ConstraintRelationId, DependDependerIndexId, DEPENDENCY_INTERNAL, DependRelationId, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, Int32GetDatum, InvalidOid, NULL, ObjectIdGetDatum, RelationRelationId, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by generateClonedIndexStmt(), RenameRelationInternal(), and transformIndexConstraint().

677 {
678  Oid constraintId = InvalidOid;
679  Relation depRel;
680  ScanKeyData key[3];
681  SysScanDesc scan;
682  HeapTuple tup;
683 
684  /* Search the dependency table for the index */
686 
687  ScanKeyInit(&key[0],
689  BTEqualStrategyNumber, F_OIDEQ,
691  ScanKeyInit(&key[1],
693  BTEqualStrategyNumber, F_OIDEQ,
694  ObjectIdGetDatum(indexId));
695  ScanKeyInit(&key[2],
697  BTEqualStrategyNumber, F_INT4EQ,
698  Int32GetDatum(0));
699 
700  scan = systable_beginscan(depRel, DependDependerIndexId, true,
701  NULL, 3, key);
702 
703  while (HeapTupleIsValid(tup = systable_getnext(scan)))
704  {
705  Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
706 
707  /*
708  * We assume any internal dependency on a constraint must be what we
709  * are looking for.
710  */
711  if (deprec->refclassid == ConstraintRelationId &&
712  deprec->refobjsubid == 0 &&
713  deprec->deptype == DEPENDENCY_INTERNAL)
714  {
715  constraintId = deprec->refobjid;
716  break;
717  }
718  }
719 
720  systable_endscan(scan);
721  heap_close(depRel, AccessShareLock);
722 
723  return constraintId;
724 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define RelationRelationId
Definition: pg_class.h:29
#define DependDependerIndexId
Definition: indexing.h:145
#define DependRelationId
Definition: pg_depend.h:29
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
#define Anum_pg_depend_objsubid
Definition: pg_depend.h:70
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define Int32GetDatum(X)
Definition: postgres.h:487
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define ConstraintRelationId
Definition: pg_constraint.h:29
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
#define BTEqualStrategyNumber
Definition: stratnum.h:31
Oid getExtensionOfObject ( Oid  classId,
Oid  objectId 
)

Definition at line 447 of file pg_depend.c.

References AccessShareLock, Anum_pg_depend_classid, Anum_pg_depend_objid, BTEqualStrategyNumber, DependDependerIndexId, DEPENDENCY_EXTENSION, DependRelationId, ExtensionRelationId, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, InvalidOid, NULL, ObjectIdGetDatum, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterExtensionNamespace(), ExecAlterExtensionContentsStmt(), lookup_shippable(), pg_extension_config_dump(), and recordDependencyOnCurrentExtension().

448 {
449  Oid result = InvalidOid;
450  Relation depRel;
451  ScanKeyData key[2];
452  SysScanDesc scan;
453  HeapTuple tup;
454 
456 
457  ScanKeyInit(&key[0],
459  BTEqualStrategyNumber, F_OIDEQ,
460  ObjectIdGetDatum(classId));
461  ScanKeyInit(&key[1],
463  BTEqualStrategyNumber, F_OIDEQ,
464  ObjectIdGetDatum(objectId));
465 
466  scan = systable_beginscan(depRel, DependDependerIndexId, true,
467  NULL, 2, key);
468 
469  while (HeapTupleIsValid((tup = systable_getnext(scan))))
470  {
471  Form_pg_depend depform = (Form_pg_depend) GETSTRUCT(tup);
472 
473  if (depform->refclassid == ExtensionRelationId &&
474  depform->deptype == DEPENDENCY_EXTENSION)
475  {
476  result = depform->refobjid;
477  break; /* no need to keep scanning */
478  }
479  }
480 
481  systable_endscan(scan);
482 
483  heap_close(depRel, AccessShareLock);
484 
485  return result;
486 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define DependDependerIndexId
Definition: indexing.h:145
#define DependRelationId
Definition: pg_depend.h:29
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
#define ExtensionRelationId
Definition: pg_extension.h:29
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
#define BTEqualStrategyNumber
Definition: stratnum.h:31
ObjectClass getObjectClass ( const ObjectAddress object)

Definition at line 2312 of file dependency.c.

References AccessMethodOperatorRelationId, AccessMethodProcedureRelationId, AccessMethodRelationId, AttrDefaultRelationId, AuthIdRelationId, CastRelationId, ObjectAddress::classId, CollationRelationId, ConstraintRelationId, ConversionRelationId, DatabaseRelationId, DefaultAclRelationId, elog, ERROR, EventTriggerRelationId, ExtensionRelationId, ForeignDataWrapperRelationId, ForeignServerRelationId, LanguageRelationId, LargeObjectRelationId, NamespaceRelationId, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OperatorClassRelationId, OperatorFamilyRelationId, OperatorRelationId, PolicyRelationId, ProcedureRelationId, PublicationRelationId, PublicationRelRelationId, RelationRelationId, RewriteRelationId, SubscriptionRelationId, TableSpaceRelationId, TransformRelationId, TriggerRelationId, TSConfigRelationId, TSDictionaryRelationId, TSParserRelationId, TSTemplateRelationId, TypeRelationId, and UserMappingRelationId.

Referenced by AlterObjectNamespace_oid(), ATExecAlterColumnType(), deleteObjectsInList(), doDeletion(), EventTriggerSQLDropAddObject(), getObjectDescription(), getObjectIdentityParts(), and getObjectTypeDescription().

2313 {
2314  /* only pg_class entries can have nonzero objectSubId */
2315  if (object->classId != RelationRelationId &&
2316  object->objectSubId != 0)
2317  elog(ERROR, "invalid non-zero objectSubId for object class %u",
2318  object->classId);
2319 
2320  switch (object->classId)
2321  {
2322  case RelationRelationId:
2323  /* caller must check objectSubId */
2324  return OCLASS_CLASS;
2325 
2326  case ProcedureRelationId:
2327  return OCLASS_PROC;
2328 
2329  case TypeRelationId:
2330  return OCLASS_TYPE;
2331 
2332  case CastRelationId:
2333  return OCLASS_CAST;
2334 
2335  case CollationRelationId:
2336  return OCLASS_COLLATION;
2337 
2338  case ConstraintRelationId:
2339  return OCLASS_CONSTRAINT;
2340 
2341  case ConversionRelationId:
2342  return OCLASS_CONVERSION;
2343 
2344  case AttrDefaultRelationId:
2345  return OCLASS_DEFAULT;
2346 
2347  case LanguageRelationId:
2348  return OCLASS_LANGUAGE;
2349 
2350  case LargeObjectRelationId:
2351  return OCLASS_LARGEOBJECT;
2352 
2353  case OperatorRelationId:
2354  return OCLASS_OPERATOR;
2355 
2357  return OCLASS_OPCLASS;
2358 
2360  return OCLASS_OPFAMILY;
2361 
2363  return OCLASS_AM;
2364 
2366  return OCLASS_AMOP;
2367 
2369  return OCLASS_AMPROC;
2370 
2371  case RewriteRelationId:
2372  return OCLASS_REWRITE;
2373 
2374  case TriggerRelationId:
2375  return OCLASS_TRIGGER;
2376 
2377  case NamespaceRelationId:
2378  return OCLASS_SCHEMA;
2379 
2380  case TSParserRelationId:
2381  return OCLASS_TSPARSER;
2382 
2384  return OCLASS_TSDICT;
2385 
2386  case TSTemplateRelationId:
2387  return OCLASS_TSTEMPLATE;
2388 
2389  case TSConfigRelationId:
2390  return OCLASS_TSCONFIG;
2391 
2392  case AuthIdRelationId:
2393  return OCLASS_ROLE;
2394 
2395  case DatabaseRelationId:
2396  return OCLASS_DATABASE;
2397 
2398  case TableSpaceRelationId:
2399  return OCLASS_TBLSPACE;
2400 
2402  return OCLASS_FDW;
2403 
2405  return OCLASS_FOREIGN_SERVER;
2406 
2407  case UserMappingRelationId:
2408  return OCLASS_USER_MAPPING;
2409 
2410  case DefaultAclRelationId:
2411  return OCLASS_DEFACL;
2412 
2413  case ExtensionRelationId:
2414  return OCLASS_EXTENSION;
2415 
2417  return OCLASS_EVENT_TRIGGER;
2418 
2419  case PolicyRelationId:
2420  return OCLASS_POLICY;
2421 
2422  case PublicationRelationId:
2423  return OCLASS_PUBLICATION;
2424 
2426  return OCLASS_PUBLICATION_REL;
2427 
2429  return OCLASS_SUBSCRIPTION;
2430 
2431  case TransformRelationId:
2432  return OCLASS_TRANSFORM;
2433  }
2434 
2435  /* shouldn't get here */
2436  elog(ERROR, "unrecognized object class: %u", object->classId);
2437  return OCLASS_CLASS; /* keep compiler quiet */
2438 }
#define NamespaceRelationId
Definition: pg_namespace.h:34
#define OperatorRelationId
Definition: pg_operator.h:32
#define TransformRelationId
Definition: pg_transform.h:25
#define ProcedureRelationId
Definition: pg_proc.h:33
#define DatabaseRelationId
Definition: pg_database.h:29
#define RelationRelationId
Definition: pg_class.h:29
#define OperatorClassRelationId
Definition: pg_opclass.h:49
#define OperatorFamilyRelationId
Definition: pg_opfamily.h:29
#define PublicationRelationId
#define TypeRelationId
Definition: pg_type.h:34
#define DefaultAclRelationId
#define AccessMethodOperatorRelationId
Definition: pg_amop.h:54
#define PublicationRelRelationId
#define AuthIdRelationId
Definition: pg_authid.h:42
#define TSConfigRelationId
Definition: pg_ts_config.h:31
#define ERROR
Definition: elog.h:43
#define TSDictionaryRelationId
Definition: pg_ts_dict.h:31
#define SubscriptionRelationId
#define AccessMethodRelationId
Definition: pg_am.h:32
#define TSParserRelationId
Definition: pg_ts_parser.h:31
#define CollationRelationId
Definition: pg_collation.h:30
#define PolicyRelationId
Definition: pg_policy.h:19
#define RewriteRelationId
Definition: pg_rewrite.h:32
#define ForeignServerRelationId
#define EventTriggerRelationId
#define TriggerRelationId
Definition: pg_trigger.h:34
#define CastRelationId
Definition: pg_cast.h:31
#define ForeignDataWrapperRelationId
#define TableSpaceRelationId
Definition: pg_tablespace.h:29
#define UserMappingRelationId
#define LanguageRelationId
Definition: pg_language.h:29
#define ConstraintRelationId
Definition: pg_constraint.h:29
#define elog
Definition: elog.h:219
#define ExtensionRelationId
Definition: pg_extension.h:29
#define AttrDefaultRelationId
Definition: pg_attrdef.h:29
#define LargeObjectRelationId
#define AccessMethodProcedureRelationId
Definition: pg_amproc.h:43
#define ConversionRelationId
Definition: pg_conversion.h:38
#define TSTemplateRelationId
List* getOwnedSequences ( Oid  relid)

Definition at line 560 of file pg_depend.c.

References AccessShareLock, Anum_pg_depend_refclassid, Anum_pg_depend_refobjid, BTEqualStrategyNumber, DEPENDENCY_AUTO, DependReferenceIndexId, DependRelationId, get_rel_relkind(), GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, lappend_oid(), NIL, NULL, ObjectIdGetDatum, RelationRelationId, RELKIND_SEQUENCE, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by ExecuteTruncate().

561 {
562  List *result = NIL;
563  Relation depRel;
564  ScanKeyData key[2];
565  SysScanDesc scan;
566  HeapTuple tup;
567 
569 
570  ScanKeyInit(&key[0],
572  BTEqualStrategyNumber, F_OIDEQ,
574  ScanKeyInit(&key[1],
576  BTEqualStrategyNumber, F_OIDEQ,
577  ObjectIdGetDatum(relid));
578 
579  scan = systable_beginscan(depRel, DependReferenceIndexId, true,
580  NULL, 2, key);
581 
582  while (HeapTupleIsValid(tup = systable_getnext(scan)))
583  {
584  Form_pg_depend deprec = (Form_pg_depend) GETSTRUCT(tup);
585 
586  /*
587  * We assume any auto dependency of a sequence on a column must be
588  * what we are looking for. (We need the relkind test because indexes
589  * can also have auto dependencies on columns.)
590  */
591  if (deprec->classid == RelationRelationId &&
592  deprec->objsubid == 0 &&
593  deprec->refobjsubid != 0 &&
594  deprec->deptype == DEPENDENCY_AUTO &&
595  get_rel_relkind(deprec->objid) == RELKIND_SEQUENCE)
596  {
597  result = lappend_oid(result, deprec->objid);
598  }
599  }
600 
601  systable_endscan(scan);
602 
603  heap_close(depRel, AccessShareLock);
604 
605  return result;
606 }
#define NIL
Definition: pg_list.h:69
#define Anum_pg_depend_refobjid
Definition: pg_depend.h:72
#define Anum_pg_depend_refclassid
Definition: pg_depend.h:71
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1769
#define RelationRelationId
Definition: pg_class.h:29
#define DependReferenceIndexId
Definition: indexing.h:147
#define DependRelationId
Definition: pg_depend.h:29
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
List * lappend_oid(List *list, Oid datum)
Definition: list.c:164
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
Definition: pg_list.h:45
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void markSequenceUnowned ( Oid  seqId)

Definition at line 550 of file pg_depend.c.

References deleteDependencyRecordsForClass(), DEPENDENCY_AUTO, and RelationRelationId.

Referenced by process_owned_by().

551 {
554 }
#define RelationRelationId
Definition: pg_class.h:29
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
Definition: pg_depend.c:241
ObjectAddresses* new_object_addresses ( void  )

Definition at line 2026 of file dependency.c.

References ObjectAddresses::extras, ObjectAddresses::maxrefs, NULL, ObjectAddresses::numrefs, palloc(), and ObjectAddresses::refs.

Referenced by AlterExtensionNamespace(), AlterTableNamespace(), AlterTypeNamespace(), makeConfigurationDependencies(), performDeletion(), performMultipleDeletions(), recordDependencyOnExpr(), recordDependencyOnSingleRelExpr(), RemoveObjects(), RemoveRelations(), and shdepDropOwned().

2027 {
2028  ObjectAddresses *addrs;
2029 
2030  addrs = palloc(sizeof(ObjectAddresses));
2031 
2032  addrs->numrefs = 0;
2033  addrs->maxrefs = 32;
2034  addrs->refs = (ObjectAddress *)
2035  palloc(addrs->maxrefs * sizeof(ObjectAddress));
2036  addrs->extras = NULL; /* until/unless needed */
2037 
2038  return addrs;
2039 }
ObjectAddress * refs
Definition: dependency.c:110
#define NULL
Definition: c.h:226
ObjectAddressExtra * extras
Definition: dependency.c:111
void * palloc(Size size)
Definition: mcxt.c:891
bool object_address_present ( const ObjectAddress object,
const ObjectAddresses addrs 
)

Definition at line 2141 of file dependency.c.

References ObjectAddress::classId, i, ObjectAddresses::numrefs, ObjectAddress::objectId, ObjectAddress::objectSubId, and ObjectAddresses::refs.

Referenced by AlterConstraintNamespaces(), AlterIndexNamespaces(), AlterRelationNamespaceInternal(), AlterTypeNamespaceInternal(), and findDependentObjects().

2143 {
2144  int i;
2145 
2146  for (i = addrs->numrefs - 1; i >= 0; i--)
2147  {
2148  const ObjectAddress *thisobj = addrs->refs + i;
2149 
2150  if (object->classId == thisobj->classId &&
2151  object->objectId == thisobj->objectId)
2152  {
2153  if (object->objectSubId == thisobj->objectSubId ||
2154  thisobj->objectSubId == 0)
2155  return true;
2156  }
2157  }
2158 
2159  return false;
2160 }
ObjectAddress * refs
Definition: dependency.c:110
int i
void performDeletion ( const ObjectAddress object,
DropBehavior  behavior,
int  flags 
)

Definition at line 301 of file dependency.c.

References AcquireDeletionLock(), deleteObjectsInList(), DependRelationId, DEPFLAG_ORIGINAL, findDependentObjects(), free_object_addresses(), heap_close, heap_open(), new_object_addresses(), NULL, reportDependentObjects(), and RowExclusiveLock.

Referenced by AlterDomainDropConstraint(), ATExecDropColumn(), ATExecDropConstraint(), ATPostAlterTypeCleanup(), DefineQueryRewrite(), do_autovacuum(), dropOperators(), dropProcedures(), finish_heap_swap(), inv_drop(), PreCommit_on_commit_actions(), PublicationDropTables(), RemoveAttrDefault(), RemoveTempRelations(), RemoveUserMapping(), and SetDefaultACL().

303 {
304  Relation depRel;
305  ObjectAddresses *targetObjects;
306 
307  /*
308  * We save some cycles by opening pg_depend just once and passing the
309  * Relation pointer down to all the recursive deletion steps.
310  */
312 
313  /*
314  * Acquire deletion lock on the target object. (Ideally the caller has
315  * done this already, but many places are sloppy about it.)
316  */
317  AcquireDeletionLock(object, 0);
318 
319  /*
320  * Construct a list of objects to delete (ie, the given object plus
321  * everything directly or indirectly dependent on it).
322  */
323  targetObjects = new_object_addresses();
324 
325  findDependentObjects(object,
327  flags,
328  NULL, /* empty stack */
329  targetObjects,
330  NULL, /* no pendingObjects */
331  &depRel);
332 
333  /*
334  * Check if deletion is allowed, and report about cascaded deletes.
335  */
336  reportDependentObjects(targetObjects,
337  behavior,
338  flags,
339  object);
340 
341  /* do the deed */
342  deleteObjectsInList(targetObjects, &depRel, flags);
343 
344  /* And clean up */
345  free_object_addresses(targetObjects);
346 
347  heap_close(depRel, RowExclusiveLock);
348 }
static void findDependentObjects(const ObjectAddress *object, int objflags, int flags, ObjectAddressStack *stack, ObjectAddresses *targetObjects, const ObjectAddresses *pendingObjects, Relation *depRel)
Definition: dependency.c:460
#define DependRelationId
Definition: pg_depend.h:29
#define heap_close(r, l)
Definition: heapam.h:97
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2026
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2297
#define DEPFLAG_ORIGINAL
Definition: dependency.c:99
#define RowExclusiveLock
Definition: lockdefs.h:38
static void reportDependentObjects(const ObjectAddresses *targetObjects, DropBehavior behavior, int flags, const ObjectAddress *origObject)
Definition: dependency.c:826
static void AcquireDeletionLock(const ObjectAddress *object, int flags)
Definition: dependency.c:1280
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
static void deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel, int flags)
Definition: dependency.c:217
void performMultipleDeletions ( const ObjectAddresses objects,
DropBehavior  behavior,
int  flags 
)

Definition at line 360 of file dependency.c.

References AcquireDeletionLock(), deleteObjectsInList(), DependRelationId, DEPFLAG_ORIGINAL, findDependentObjects(), free_object_addresses(), heap_close, heap_open(), i, new_object_addresses(), NULL, ObjectAddresses::numrefs, ObjectAddresses::refs, reportDependentObjects(), and RowExclusiveLock.

Referenced by RemoveObjects(), RemoveRelations(), and shdepDropOwned().

362 {
363  Relation depRel;
364  ObjectAddresses *targetObjects;
365  int i;
366 
367  /* No work if no objects... */
368  if (objects->numrefs <= 0)
369  return;
370 
371  /*
372  * We save some cycles by opening pg_depend just once and passing the
373  * Relation pointer down to all the recursive deletion steps.
374  */
376 
377  /*
378  * Construct a list of objects to delete (ie, the given objects plus
379  * everything directly or indirectly dependent on them). Note that
380  * because we pass the whole objects list as pendingObjects context, we
381  * won't get a failure from trying to delete an object that is internally
382  * dependent on another one in the list; we'll just skip that object and
383  * delete it when we reach its owner.
384  */
385  targetObjects = new_object_addresses();
386 
387  for (i = 0; i < objects->numrefs; i++)
388  {
389  const ObjectAddress *thisobj = objects->refs + i;
390 
391  /*
392  * Acquire deletion lock on each target object. (Ideally the caller
393  * has done this already, but many places are sloppy about it.)
394  */
395  AcquireDeletionLock(thisobj, flags);
396 
397  findDependentObjects(thisobj,
399  flags,
400  NULL, /* empty stack */
401  targetObjects,
402  objects,
403  &depRel);
404  }
405 
406  /*
407  * Check if deletion is allowed, and report about cascaded deletes.
408  *
409  * If there's exactly one object being deleted, report it the same way as
410  * in performDeletion(), else we have to be vaguer.
411  */
412  reportDependentObjects(targetObjects,
413  behavior,
414  flags,
415  (objects->numrefs == 1 ? objects->refs : NULL));
416 
417  /* do the deed */
418  deleteObjectsInList(targetObjects, &depRel, flags);
419 
420  /* And clean up */
421  free_object_addresses(targetObjects);
422 
423  heap_close(depRel, RowExclusiveLock);
424 }
static void findDependentObjects(const ObjectAddress *object, int objflags, int flags, ObjectAddressStack *stack, ObjectAddresses *targetObjects, const ObjectAddresses *pendingObjects, Relation *depRel)
Definition: dependency.c:460
#define DependRelationId
Definition: pg_depend.h:29
#define heap_close(r, l)
Definition: heapam.h:97
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2026
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2297
#define DEPFLAG_ORIGINAL
Definition: dependency.c:99
ObjectAddress * refs
Definition: dependency.c:110
#define RowExclusiveLock
Definition: lockdefs.h:38
static void reportDependentObjects(const ObjectAddresses *targetObjects, DropBehavior behavior, int flags, const ObjectAddress *origObject)
Definition: dependency.c:826
static void AcquireDeletionLock(const ObjectAddress *object, int flags)
Definition: dependency.c:1280
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define NULL
Definition: c.h:226
int i
static void deleteObjectsInList(ObjectAddresses *targetObjects, Relation *depRel, int flags)
Definition: dependency.c:217
void record_object_address_dependencies ( const ObjectAddress depender,
ObjectAddresses referenced,
DependencyType  behavior 
)

Definition at line 2283 of file dependency.c.

References eliminate_duplicate_dependencies(), ObjectAddresses::numrefs, recordMultipleDependencies(), and ObjectAddresses::refs.

Referenced by makeConfigurationDependencies().

2286 {
2288  recordMultipleDependencies(depender,
2289  referenced->refs, referenced->numrefs,
2290  behavior);
2291 }
static void eliminate_duplicate_dependencies(ObjectAddresses *addrs)
Definition: dependency.c:1935
ObjectAddress * refs
Definition: dependency.c:110
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:56
void recordDependencyOn ( const ObjectAddress depender,
const ObjectAddress referenced,
DependencyType  behavior 
)

Definition at line 44 of file pg_depend.c.

References recordMultipleDependencies().

Referenced by add_column_collation_dependency(), add_column_datatype_dependency(), AddNewAttributeTuples(), AggregateCreate(), AlterForeignDataWrapper(), AlterPolicy(), ApplyExtensionUpdates(), ATExecAddOf(), CollationCreate(), ConversionCreate(), create_proc_lang(), create_toast_table(), CreateAccessMethod(), CreateCast(), CreateConstraintEntry(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreatePolicy(), CreateTransform(), CreateTrigger(), CreateUserMapping(), DefineOpClass(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), GenerateTypeDependencies(), heap_create_with_catalog(), index_constraint_create(), index_create(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertRule(), makeDictionaryDependencies(), makeOperatorDependencies(), makeParserDependencies(), makeRangeConstructors(), makeTSTemplateDependencies(), ProcedureCreate(), process_owned_by(), publication_add_relation(), RangeCreate(), recordDependencyOnCurrentExtension(), RemoveRoleFromObjectPolicy(), SetDefaultACL(), StoreAttrDefault(), StoreCatalogInheritance1(), storeOperators(), StorePartitionKey(), storeProcedures(), and swap_relation_files().

47 {
48  recordMultipleDependencies(depender, referenced, 1, behavior);
49 }
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:56
void recordDependencyOnCurrentExtension ( const ObjectAddress object,
bool  isReplace 
)

Definition at line 139 of file pg_depend.c.

References Assert, ObjectAddress::classId, creating_extension, CurrentExtensionObject, DEPENDENCY_EXTENSION, ereport, errcode(), errmsg(), ERROR, ExtensionRelationId, get_extension_name(), getExtensionOfObject(), getObjectDescription(), ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, and recordDependencyOn().

Referenced by CollationCreate(), ConversionCreate(), create_proc_lang(), CreateAccessMethod(), CreateCast(), CreateForeignDataWrapper(), CreateForeignServer(), CreateOpFamily(), CreateTransform(), CreateUserMapping(), DefineOpClass(), GenerateTypeDependencies(), heap_create_with_catalog(), insert_event_trigger_tuple(), makeConfigurationDependencies(), makeDictionaryDependencies(), makeOperatorDependencies(), makeParserDependencies(), makeTSTemplateDependencies(), NamespaceCreate(), and ProcedureCreate().

141 {
142  /* Only whole objects can be extension members */
143  Assert(object->objectSubId == 0);
144 
145  if (creating_extension)
146  {
147  ObjectAddress extension;
148 
149  /* Only need to check for existing membership if isReplace */
150  if (isReplace)
151  {
152  Oid oldext;
153 
154  oldext = getExtensionOfObject(object->classId, object->objectId);
155  if (OidIsValid(oldext))
156  {
157  /* If already a member of this extension, nothing to do */
158  if (oldext == CurrentExtensionObject)
159  return;
160  /* Already a member of some other extension, so reject */
161  ereport(ERROR,
162  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
163  errmsg("%s is already a member of extension \"%s\"",
164  getObjectDescription(object),
165  get_extension_name(oldext))));
166  }
167  }
168 
169  /* OK, record it as a member of CurrentExtensionObject */
170  extension.classId = ExtensionRelationId;
171  extension.objectId = CurrentExtensionObject;
172  extension.objectSubId = 0;
173 
174  recordDependencyOn(object, &extension, DEPENDENCY_EXTENSION);
175  }
176 }
Oid CurrentExtensionObject
Definition: extension.c:68
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:447
char * get_extension_name(Oid ext_oid)
Definition: extension.c:179
int errcode(int sqlerrcode)
Definition: elog.c:575
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
char * getObjectDescription(const ObjectAddress *object)
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
bool creating_extension
Definition: extension.c:67
#define Assert(condition)
Definition: c.h:671
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ExtensionRelationId
Definition: pg_extension.h:29
void recordDependencyOnExpr ( const ObjectAddress depender,
Node expr,
List rtable,
DependencyType  behavior 
)

Definition at line 1332 of file dependency.c.

References find_expr_references_context::addrs, eliminate_duplicate_dependencies(), find_expr_references_walker(), free_object_addresses(), list_make1, new_object_addresses(), ObjectAddresses::numrefs, recordMultipleDependencies(), ObjectAddresses::refs, and find_expr_references_context::rtables.

Referenced by AlterPolicy(), CreatePolicy(), CreateTrigger(), GenerateTypeDependencies(), InsertRule(), ProcedureCreate(), RemoveRoleFromObjectPolicy(), and StoreAttrDefault().

1335 {
1337 
1338  context.addrs = new_object_addresses();
1339 
1340  /* Set up interpretation for Vars at varlevelsup = 0 */
1341  context.rtables = list_make1(rtable);
1342 
1343  /* Scan the expression tree for referenceable objects */
1344  find_expr_references_walker(expr, &context);
1345 
1346  /* Remove any duplicates */
1348 
1349  /* And record 'em */
1350  recordMultipleDependencies(depender,
1351  context.addrs->refs, context.addrs->numrefs,
1352  behavior);
1353 
1354  free_object_addresses(context.addrs);
1355 }
static bool find_expr_references_walker(Node *node, find_expr_references_context *context)
Definition: dependency.c:1468
ObjectAddresses * addrs
Definition: dependency.c:129
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2026
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2297
static void eliminate_duplicate_dependencies(ObjectAddresses *addrs)
Definition: dependency.c:1935
#define list_make1(x1)
Definition: pg_list.h:133
ObjectAddress * refs
Definition: dependency.c:110
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:56
void recordDependencyOnOwner ( Oid  classId,
Oid  objectId,
Oid  owner 
)

Definition at line 158 of file pg_shdepend.c.

References AuthIdRelationId, ObjectAddress::classId, ObjectAddress::objectId, ObjectAddress::objectSubId, recordSharedDependencyOn(), and SHARED_DEPENDENCY_OWNER.

Referenced by CollationCreate(), ConversionCreate(), create_proc_lang(), createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateOpFamily(), CreatePublication(), CreateSubscription(), CreateTableSpace(), CreateUserMapping(), DefineOpClass(), GenerateTypeDependencies(), heap_create_with_catalog(), insert_event_trigger_tuple(), InsertExtensionTuple(), inv_create(), makeConfigurationDependencies(), makeDictionaryDependencies(), makeOperatorDependencies(), NamespaceCreate(), ProcedureCreate(), and SetDefaultACL().

159 {
160  ObjectAddress myself,
161  referenced;
162 
163  myself.classId = classId;
164  myself.objectId = objectId;
165  myself.objectSubId = 0;
166 
167  referenced.classId = AuthIdRelationId;
168  referenced.objectId = owner;
169  referenced.objectSubId = 0;
170 
171  recordSharedDependencyOn(&myself, &referenced, SHARED_DEPENDENCY_OWNER);
172 }
void recordSharedDependencyOn(ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
Definition: pg_shdepend.c:114
#define AuthIdRelationId
Definition: pg_authid.h:42
void recordDependencyOnSingleRelExpr ( const ObjectAddress depender,
Node expr,
Oid  relId,
DependencyType  behavior,
DependencyType  self_behavior,
bool  ignore_self 
)

Definition at line 1373 of file dependency.c.

References add_exact_object_address(), find_expr_references_context::addrs, ObjectAddress::classId, eliminate_duplicate_dependencies(), find_expr_references_walker(), free_object_addresses(), list_make1, MemSet, new_object_addresses(), ObjectAddresses::numrefs, ObjectAddress::objectId, recordMultipleDependencies(), ObjectAddresses::refs, RelationRelationId, RangeTblEntry::relid, RangeTblEntry::relkind, RELKIND_RELATION, find_expr_references_context::rtables, RTE_RELATION, RangeTblEntry::rtekind, T_RangeTblEntry, and RangeTblEntry::type.

Referenced by CreateConstraintEntry(), index_create(), and StorePartitionKey().

1378 {
1380  RangeTblEntry rte;
1381 
1382  context.addrs = new_object_addresses();
1383 
1384  /* We gin up a rather bogus rangetable list to handle Vars */
1385  MemSet(&rte, 0, sizeof(rte));
1386  rte.type = T_RangeTblEntry;
1387  rte.rtekind = RTE_RELATION;
1388  rte.relid = relId;
1389  rte.relkind = RELKIND_RELATION; /* no need for exactness here */
1390 
1391  context.rtables = list_make1(list_make1(&rte));
1392 
1393  /* Scan the expression tree for referenceable objects */
1394  find_expr_references_walker(expr, &context);
1395 
1396  /* Remove any duplicates */
1398 
1399  /* Separate self-dependencies if necessary */
1400  if (behavior != self_behavior && context.addrs->numrefs > 0)
1401  {
1402  ObjectAddresses *self_addrs;
1403  ObjectAddress *outobj;
1404  int oldref,
1405  outrefs;
1406 
1407  self_addrs = new_object_addresses();
1408 
1409  outobj = context.addrs->refs;
1410  outrefs = 0;
1411  for (oldref = 0; oldref < context.addrs->numrefs; oldref++)
1412  {
1413  ObjectAddress *thisobj = context.addrs->refs + oldref;
1414 
1415  if (thisobj->classId == RelationRelationId &&
1416  thisobj->objectId == relId)
1417  {
1418  /* Move this ref into self_addrs */
1419  add_exact_object_address(thisobj, self_addrs);
1420  }
1421  else
1422  {
1423  /* Keep it in context.addrs */
1424  *outobj = *thisobj;
1425  outobj++;
1426  outrefs++;
1427  }
1428  }
1429  context.addrs->numrefs = outrefs;
1430 
1431  /* Record the self-dependencies */
1432  if (!ignore_self)
1433  recordMultipleDependencies(depender,
1434  self_addrs->refs, self_addrs->numrefs,
1435  self_behavior);
1436 
1437  free_object_addresses(self_addrs);
1438  }
1439 
1440  /* Record the external dependencies */
1441  recordMultipleDependencies(depender,
1442  context.addrs->refs, context.addrs->numrefs,
1443  behavior);
1444 
1445  free_object_addresses(context.addrs);
1446 }
static bool find_expr_references_walker(Node *node, find_expr_references_context *context)
Definition: dependency.c:1468
ObjectAddresses * addrs
Definition: dependency.c:129
#define RelationRelationId
Definition: pg_class.h:29
#define MemSet(start, val, len)
Definition: c.h:853
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2081
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2026
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2297
static void eliminate_duplicate_dependencies(ObjectAddresses *addrs)
Definition: dependency.c:1935
#define list_make1(x1)
Definition: pg_list.h:133
ObjectAddress * refs
Definition: dependency.c:110
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:56
RTEKind rtekind
Definition: parsenodes.h:882
NodeTag type
Definition: parsenodes.h:880
#define RELKIND_RELATION
Definition: pg_class.h:160
void recordMultipleDependencies ( const ObjectAddress depender,
const ObjectAddress referenced,
int  nreferenced,
DependencyType  behavior 
)

Definition at line 56 of file pg_depend.c.

References Anum_pg_depend_classid, Anum_pg_depend_deptype, Anum_pg_depend_objid, Anum_pg_depend_objsubid, Anum_pg_depend_refclassid, Anum_pg_depend_refobjid, Anum_pg_depend_refobjsubid, CatalogCloseIndexes(), CatalogOpenIndexes(), CatalogTupleInsertWithInfo(), CharGetDatum, ObjectAddress::classId, DependRelationId, heap_close, heap_form_tuple(), heap_freetuple(), heap_open(), i, Int32GetDatum, IsBootstrapProcessingMode, isObjectPinned(), Natts_pg_depend, NULL, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, RelationData::rd_att, RowExclusiveLock, and values.

Referenced by record_object_address_dependencies(), recordDependencyOn(), recordDependencyOnExpr(), and recordDependencyOnSingleRelExpr().

60 {
61  Relation dependDesc;
62  CatalogIndexState indstate;
63  HeapTuple tup;
64  int i;
65  bool nulls[Natts_pg_depend];
67 
68  if (nreferenced <= 0)
69  return; /* nothing to do */
70 
71  /*
72  * During bootstrap, do nothing since pg_depend may not exist yet. initdb
73  * will fill in appropriate pg_depend entries after bootstrap.
74  */
76  return;
77 
79 
80  /* Don't open indexes unless we need to make an update */
81  indstate = NULL;
82 
83  memset(nulls, false, sizeof(nulls));
84 
85  for (i = 0; i < nreferenced; i++, referenced++)
86  {
87  /*
88  * If the referenced object is pinned by the system, there's no real
89  * need to record dependencies on it. This saves lots of space in
90  * pg_depend, so it's worth the time taken to check.
91  */
92  if (!isObjectPinned(referenced, dependDesc))
93  {
94  /*
95  * Record the Dependency. Note we don't bother to check for
96  * duplicate dependencies; there's no harm in them.
97  */
98  values[Anum_pg_depend_classid - 1] = ObjectIdGetDatum(depender->classId);
99  values[Anum_pg_depend_objid - 1] = ObjectIdGetDatum(depender->objectId);
100  values[Anum_pg_depend_objsubid - 1] = Int32GetDatum(depender->objectSubId);
101 
102  values[Anum_pg_depend_refclassid - 1] = ObjectIdGetDatum(referenced->classId);
103  values[Anum_pg_depend_refobjid - 1] = ObjectIdGetDatum(referenced->objectId);
104  values[Anum_pg_depend_refobjsubid - 1] = Int32GetDatum(referenced->objectSubId);
105 
106  values[Anum_pg_depend_deptype - 1] = CharGetDatum((char) behavior);
107 
108  tup = heap_form_tuple(dependDesc->rd_att, values, nulls);
109 
110  /* fetch index info only when we know we need it */
111  if (indstate == NULL)
112  indstate = CatalogOpenIndexes(dependDesc);
113 
114  CatalogTupleInsertWithInfo(dependDesc, tup, indstate);
115 
116  heap_freetuple(tup);
117  }
118  }
119 
120  if (indstate != NULL)
121  CatalogCloseIndexes(indstate);
122 
123  heap_close(dependDesc, RowExclusiveLock);
124 }
#define Anum_pg_depend_refobjid
Definition: pg_depend.h:72
#define Anum_pg_depend_refobjsubid
Definition: pg_depend.h:73
#define Anum_pg_depend_refclassid
Definition: pg_depend.h:71
#define DependRelationId
Definition: pg_depend.h:29
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1374
#define Anum_pg_depend_objsubid
Definition: pg_depend.h:70
static bool isObjectPinned(const ObjectAddress *object, Relation rel)
Definition: pg_depend.c:389
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define Natts_pg_depend
Definition: pg_depend.h:67
#define RowExclusiveLock
Definition: lockdefs.h:38
uintptr_t Datum
Definition: postgres.h:374
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
TupleDesc rd_att
Definition: rel.h:114
#define NULL
Definition: c.h:226
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Definition: indexing.c:40
#define CharGetDatum(X)
Definition: postgres.h:424
static Datum values[MAXATTR]
Definition: bootstrap.c:162
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
#define Int32GetDatum(X)
Definition: postgres.h:487
int i
#define Anum_pg_depend_deptype
Definition: pg_depend.h:74
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:58
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
Oid CatalogTupleInsertWithInfo(Relation heapRel, HeapTuple tup, CatalogIndexState indstate)
Definition: indexing.c:186
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
void recordSharedDependencyOn ( ObjectAddress depender,
ObjectAddress referenced,
SharedDependencyType  deptype 
)

Definition at line 114 of file pg_shdepend.c.

References Assert, ObjectAddress::classId, heap_close, heap_open(), IsBootstrapProcessingMode, isSharedObjectPinned(), ObjectAddress::objectId, ObjectAddress::objectSubId, RowExclusiveLock, SharedDependRelationId, and shdepAddDependency().

Referenced by AlterPolicy(), CreatePolicy(), recordDependencyOnOwner(), and RemoveRoleFromObjectPolicy().

117 {
118  Relation sdepRel;
119 
120  /*
121  * Objects in pg_shdepend can't have SubIds.
122  */
123  Assert(depender->objectSubId == 0);
124  Assert(referenced->objectSubId == 0);
125 
126  /*
127  * During bootstrap, do nothing since pg_shdepend may not exist yet.
128  * initdb will fill in appropriate pg_shdepend entries after bootstrap.
129  */
131  return;
132 
134 
135  /* If the referenced object is pinned, do nothing. */
136  if (!isSharedObjectPinned(referenced->classId, referenced->objectId,
137  sdepRel))
138  {
139  shdepAddDependency(sdepRel, depender->classId, depender->objectId,
140  depender->objectSubId,
141  referenced->classId, referenced->objectId,
142  deptype);
143  }
144 
145  heap_close(sdepRel, RowExclusiveLock);
146 }
static bool isSharedObjectPinned(Oid classId, Oid objectId, Relation sdepRel)
Definition: pg_shdepend.c:1110
#define SharedDependRelationId
Definition: pg_shdepend.h:29
static void shdepAddDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
Definition: pg_shdepend.c:844
#define heap_close(r, l)
Definition: heapam.h:97
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define Assert(condition)
Definition: c.h:671
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:365
bool sequenceIsOwned ( Oid  seqId,
Oid tableId,
int32 colId 
)

Definition at line 500 of file pg_depend.c.

References AccessShareLock, Anum_pg_depend_classid, Anum_pg_depend_objid, BTEqualStrategyNumber, DependDependerIndexId, DEPENDENCY_AUTO, DependRelationId, GETSTRUCT, heap_close, heap_open(), HeapTupleIsValid, NULL, ObjectIdGetDatum, RelationRelationId, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterTableNamespace(), and ATExecChangeOwner().

501 {
502  bool ret = false;
503  Relation depRel;
504  ScanKeyData key[2];
505  SysScanDesc scan;
506  HeapTuple tup;
507 
509 
510  ScanKeyInit(&key[0],
512  BTEqualStrategyNumber, F_OIDEQ,
514  ScanKeyInit(&key[1],
516  BTEqualStrategyNumber, F_OIDEQ,
517  ObjectIdGetDatum(seqId));
518 
519  scan = systable_beginscan(depRel, DependDependerIndexId, true,
520  NULL, 2, key);
521 
522  while (HeapTupleIsValid((tup = systable_getnext(scan))))
523  {
524  Form_pg_depend depform = (Form_pg_depend) GETSTRUCT(tup);
525 
526  if (depform->refclassid == RelationRelationId &&
527  depform->deptype == DEPENDENCY_AUTO)
528  {
529  *tableId = depform->refobjid;
530  *colId = depform->refobjsubid;
531  ret = true;
532  break; /* no need to keep scanning */
533  }
534  }
535 
536  systable_endscan(scan);
537 
538  heap_close(depRel, AccessShareLock);
539 
540  return ret;
541 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define RelationRelationId
Definition: pg_class.h:29
#define DependDependerIndexId
Definition: indexing.h:145
#define DependRelationId
Definition: pg_depend.h:29
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
FormData_pg_depend * Form_pg_depend
Definition: pg_depend.h:61
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define Anum_pg_depend_classid
Definition: pg_depend.h:68
#define Anum_pg_depend_objid
Definition: pg_depend.h:69
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void shdepDropOwned ( List relids,
DropBehavior  behavior 
)

Definition at line 1162 of file pg_shdepend.c.

References add_exact_object_address(), Anum_pg_shdepend_refclassid, Anum_pg_shdepend_refobjid, AuthIdRelationId, BTEqualStrategyNumber, ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, free_object_addresses(), getObjectDescription(), GETSTRUCT, heap_close, heap_open(), InvalidOid, isSharedObjectPinned(), lfirst_oid, MyDatabaseId, new_object_addresses(), NULL, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, performMultipleDeletions(), RemoveRoleFromObjectACL(), RemoveRoleFromObjectPolicy(), RowExclusiveLock, ScanKeyInit(), SHARED_DEPENDENCY_ACL, SHARED_DEPENDENCY_INVALID, SHARED_DEPENDENCY_OWNER, SHARED_DEPENDENCY_PIN, SHARED_DEPENDENCY_POLICY, SharedDependReferenceIndexId, SharedDependRelationId, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by DropOwnedObjects().

1163 {
1164  Relation sdepRel;
1165  ListCell *cell;
1166  ObjectAddresses *deleteobjs;
1167 
1168  deleteobjs = new_object_addresses();
1169 
1170  /*
1171  * We don't need this strong a lock here, but we'll call routines that
1172  * acquire RowExclusiveLock. Better get that right now to avoid potential
1173  * deadlock failures.
1174  */
1176 
1177  /*
1178  * For each role, find the dependent objects and drop them using the
1179  * regular (non-shared) dependency management.
1180  */
1181  foreach(cell, roleids)
1182  {
1183  Oid roleid = lfirst_oid(cell);
1184  ScanKeyData key[2];
1185  SysScanDesc scan;
1186  HeapTuple tuple;
1187 
1188  /* Doesn't work for pinned objects */
1189  if (isSharedObjectPinned(AuthIdRelationId, roleid, sdepRel))
1190  {
1191  ObjectAddress obj;
1192 
1193  obj.classId = AuthIdRelationId;
1194  obj.objectId = roleid;
1195  obj.objectSubId = 0;
1196 
1197  ereport(ERROR,
1198  (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1199  errmsg("cannot drop objects owned by %s because they are "
1200  "required by the database system",
1201  getObjectDescription(&obj))));
1202  }
1203 
1204  ScanKeyInit(&key[0],
1206  BTEqualStrategyNumber, F_OIDEQ,
1208  ScanKeyInit(&key[1],
1210  BTEqualStrategyNumber, F_OIDEQ,
1211  ObjectIdGetDatum(roleid));
1212 
1213  scan = systable_beginscan(sdepRel, SharedDependReferenceIndexId, true,
1214  NULL, 2, key);
1215 
1216  while ((tuple = systable_getnext(scan)) != NULL)
1217  {
1218  Form_pg_shdepend sdepForm = (Form_pg_shdepend) GETSTRUCT(tuple);
1219  ObjectAddress obj;
1220 
1221  /*
1222  * We only operate on shared objects and objects in the current
1223  * database
1224  */
1225  if (sdepForm->dbid != MyDatabaseId &&
1226  sdepForm->dbid != InvalidOid)
1227  continue;
1228 
1229  switch (sdepForm->deptype)
1230  {
1231  /* Shouldn't happen */
1232  case SHARED_DEPENDENCY_PIN:
1234  elog(ERROR, "unexpected dependency type");
1235  break;
1236  case SHARED_DEPENDENCY_ACL:
1237  RemoveRoleFromObjectACL(roleid,
1238  sdepForm->classid,
1239  sdepForm->objid);
1240  break;
1242  /* If unable to remove role from policy, remove policy. */
1243  if (!RemoveRoleFromObjectPolicy(roleid,
1244  sdepForm->classid,
1245  sdepForm->objid))
1246  {
1247  obj.classId = sdepForm->classid;
1248  obj.objectId = sdepForm->objid;
1249  obj.objectSubId = sdepForm->objsubid;
1250  add_exact_object_address(&obj, deleteobjs);
1251  }
1252  break;
1254  /* If a local object, save it for deletion below */
1255  if (sdepForm->dbid == MyDatabaseId)
1256  {
1257  obj.classId = sdepForm->classid;
1258  obj.objectId = sdepForm->objid;
1259  obj.objectSubId = sdepForm->objsubid;
1260  add_exact_object_address(&obj, deleteobjs);
1261  }
1262  break;
1263  }
1264  }
1265 
1266  systable_endscan(scan);
1267  }
1268 
1269  /* the dependency mechanism does the actual work */
1270  performMultipleDeletions(deleteobjs, behavior, 0);
1271 
1272  heap_close(sdepRel, RowExclusiveLock);
1273 
1274  free_object_addresses(deleteobjs);
1275 }
#define Anum_pg_shdepend_refclassid
Definition: pg_shdepend.h:75
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
static bool isSharedObjectPinned(Oid classId, Oid objectId, Relation sdepRel)
Definition: pg_shdepend.c:1110
#define SharedDependRelationId
Definition: pg_shdepend.h:29
FormData_pg_shdepend * Form_pg_shdepend
Definition: pg_shdepend.h:64
int errcode(int sqlerrcode)
Definition: elog.c:575
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2081
#define heap_close(r, l)
Definition: heapam.h:97
void RemoveRoleFromObjectACL(Oid roleid, Oid classid, Oid objid)
Definition: aclchk.c:1326
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2026
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2297
unsigned int Oid
Definition: postgres_ext.h:31
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
char * getObjectDescription(const ObjectAddress *object)
#define AuthIdRelationId
Definition: pg_authid.h:42
bool RemoveRoleFromObjectPolicy(Oid roleid, Oid classid, Oid policy_id)
Definition: policy.c:435
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define Anum_pg_shdepend_refobjid
Definition: pg_shdepend.h:76
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel, rest)
Definition: elog.h:122
Oid MyDatabaseId
Definition: globals.c:76
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:226
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
Definition: dependency.c:360
#define elog
Definition: elog.h:219
#define SharedDependReferenceIndexId
Definition: indexing.h:224
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define lfirst_oid(lc)
Definition: pg_list.h:108
void shdepLockAndCheckObject ( Oid  classId,
Oid  objectId 
)

Definition at line 986 of file pg_shdepend.c.

References AccessShareLock, AuthIdRelationId, AUTHOID, DatabaseRelationId, elog, ereport, errcode(), errmsg(), ERROR, get_database_name(), get_tablespace_name(), LockSharedObject(), NULL, ObjectIdGetDatum, pfree(), SearchSysCacheExists1, tablespace, and TableSpaceRelationId.

Referenced by AlterDatabaseSet(), AlterRoleSet(), shdepAddDependency(), and shdepChangeDep().

987 {
988  /* AccessShareLock should be OK, since we are not modifying the object */
989  LockSharedObject(classId, objectId, 0, AccessShareLock);
990 
991  switch (classId)
992  {
993  case AuthIdRelationId:
995  ereport(ERROR,
996  (errcode(ERRCODE_UNDEFINED_OBJECT),
997  errmsg("role %u was concurrently dropped",
998  objectId)));
999  break;
1000 
1001  /*
1002  * Currently, this routine need not support any other shared
1003  * object types besides roles. If we wanted to record explicit
1004  * dependencies on databases or tablespaces, we'd need code along
1005  * these lines:
1006  */
1007 #ifdef NOT_USED
1008  case TableSpaceRelationId:
1009  {
1010  /* For lack of a syscache on pg_tablespace, do this: */
1011  char *tablespace = get_tablespace_name(objectId);
1012 
1013  if (tablespace == NULL)
1014  ereport(ERROR,
1015  (errcode(ERRCODE_UNDEFINED_OBJECT),
1016  errmsg("tablespace %u was concurrently dropped",
1017  objectId)));
1018  pfree(tablespace);
1019  break;
1020  }
1021 #endif
1022 
1023  case DatabaseRelationId:
1024  {
1025  /* For lack of a syscache on pg_database, do this: */
1026  char *database = get_database_name(objectId);
1027 
1028  if (database == NULL)
1029  ereport(ERROR,
1030  (errcode(ERRCODE_UNDEFINED_OBJECT),
1031  errmsg("database %u was concurrently dropped",
1032  objectId)));
1033  pfree(database);
1034  break;
1035  }
1036 
1037 
1038  default:
1039  elog(ERROR, "unrecognized shared classId: %u", classId);
1040  }
1041 }
#define DatabaseRelationId
Definition: pg_database.h:29
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:575
#define AuthIdRelationId
Definition: pg_authid.h:42
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:167
void pfree(void *pointer)
Definition: mcxt.c:992
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2048
char * tablespace
Definition: pgbench.c:146
#define ereport(elevel, rest)
Definition: elog.h:122
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:871
#define NULL
Definition: c.h:226
#define TableSpaceRelationId
Definition: pg_tablespace.h:29
int errmsg(const char *fmt,...)
Definition: elog.c:797
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1426
#define elog
Definition: elog.h:219
void shdepReassignOwned ( List relids,
Oid  newrole 
)

Definition at line 1284 of file pg_shdepend.c.

References AccessExclusiveLock, AlterEventTriggerOwner_oid(), AlterForeignDataWrapperOwner_oid(), AlterForeignServerOwner_oid(), AlterObjectOwner_internal(), AlterPublicationOwner_oid(), AlterSchemaOwner_oid(), AlterSubscriptionOwner_oid(), AlterTypeOwner_oid(), Anum_pg_shdepend_refclassid, Anum_pg_shdepend_refobjid, ATExecChangeOwner(), AuthIdRelationId, BTEqualStrategyNumber, ObjectAddress::classId, CollationRelationId, CommandCounterIncrement(), ConversionRelationId, DatabaseRelationId, DefaultAclRelationId, elog, ereport, errcode(), errmsg(), ERROR, EventTriggerRelationId, ExtensionRelationId, ForeignDataWrapperRelationId, ForeignServerRelationId, getObjectDescription(), GETSTRUCT, heap_close, heap_open(), InvalidOid, isSharedObjectPinned(), LanguageRelationId, LargeObjectMetadataRelationId, LargeObjectRelationId, lfirst_oid, MyDatabaseId, NamespaceRelationId, NoLock, NULL, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OperatorClassRelationId, OperatorFamilyRelationId, OperatorRelationId, ProcedureRelationId, PublicationRelationId, RelationRelationId, RowExclusiveLock, ScanKeyInit(), SHARED_DEPENDENCY_OWNER, SHARED_DEPENDENCY_PIN, SharedDependReferenceIndexId, SharedDependRelationId, SubscriptionRelationId, systable_beginscan(), systable_endscan(), systable_getnext(), TableSpaceRelationId, TSConfigRelationId, TSDictionaryRelationId, TypeRelationId, and UserMappingRelationId.

Referenced by ReassignOwnedObjects().

1285 {
1286  Relation sdepRel;
1287  ListCell *cell;
1288 
1289  /*
1290  * We don't need this strong a lock here, but we'll call routines that
1291  * acquire RowExclusiveLock. Better get that right now to avoid potential
1292  * deadlock problems.
1293  */
1295 
1296  foreach(cell, roleids)
1297  {
1298  SysScanDesc scan;
1299  ScanKeyData key[2];
1300  HeapTuple tuple;
1301  Oid roleid = lfirst_oid(cell);
1302 
1303  /* Refuse to work on pinned roles */
1304  if (isSharedObjectPinned(AuthIdRelationId, roleid, sdepRel))
1305  {
1306  ObjectAddress obj;
1307 
1308  obj.classId = AuthIdRelationId;
1309  obj.objectId = roleid;
1310  obj.objectSubId = 0;
1311 
1312  ereport(ERROR,
1313  (errcode(ERRCODE_DEPENDENT_OBJECTS_STILL_EXIST),
1314  errmsg("cannot reassign ownership of objects owned by %s because they are required by the database system",
1315  getObjectDescription(&obj))));
1316 
1317  /*
1318  * There's no need to tell the whole truth, which is that we
1319  * didn't track these dependencies at all ...
1320  */
1321  }
1322 
1323  ScanKeyInit(&key[0],
1325  BTEqualStrategyNumber, F_OIDEQ,
1327  ScanKeyInit(&key[1],
1329  BTEqualStrategyNumber, F_OIDEQ,
1330  ObjectIdGetDatum(roleid));
1331 
1332  scan = systable_beginscan(sdepRel, SharedDependReferenceIndexId, true,
1333  NULL, 2, key);
1334 
1335  while ((tuple = systable_getnext(scan)) != NULL)
1336  {
1337  Form_pg_shdepend sdepForm = (Form_pg_shdepend) GETSTRUCT(tuple);
1338 
1339  /*
1340  * We only operate on shared objects and objects in the current
1341  * database
1342  */
1343  if (sdepForm->dbid != MyDatabaseId &&
1344  sdepForm->dbid != InvalidOid)
1345  continue;
1346 
1347  /* Unexpected because we checked for pins above */
1348  if (sdepForm->deptype == SHARED_DEPENDENCY_PIN)
1349  elog(ERROR, "unexpected shared pin");
1350 
1351  /* We leave non-owner dependencies alone */
1352  if (sdepForm->deptype != SHARED_DEPENDENCY_OWNER)
1353  continue;
1354 
1355  /* Issue the appropriate ALTER OWNER call */
1356  switch (sdepForm->classid)
1357  {
1358  case TypeRelationId:
1359  AlterTypeOwner_oid(sdepForm->objid, newrole, true);
1360  break;
1361 
1362  case NamespaceRelationId:
1363  AlterSchemaOwner_oid(sdepForm->objid, newrole);
1364  break;
1365 
1366  case RelationRelationId:
1367 
1368  /*
1369  * Pass recursing = true so that we don't fail on indexes,
1370  * owned sequences, etc when we happen to visit them
1371  * before their parent table.
1372  */
1373  ATExecChangeOwner(sdepForm->objid, newrole, true, AccessExclusiveLock);
1374  break;
1375 
1376  case DefaultAclRelationId:
1377 
1378  /*
1379  * Ignore default ACLs; they should be handled by DROP
1380  * OWNED, not REASSIGN OWNED.
1381  */
1382  break;
1383 
1384  case UserMappingRelationId:
1385  /* ditto */
1386  break;
1387 
1389  AlterForeignServerOwner_oid(sdepForm->objid, newrole);
1390  break;
1391 
1393  AlterForeignDataWrapperOwner_oid(sdepForm->objid, newrole);
1394  break;
1395 
1397  AlterEventTriggerOwner_oid(sdepForm->objid, newrole);
1398  break;
1399 
1400  case PublicationRelationId:
1401  AlterPublicationOwner_oid(sdepForm->objid, newrole);
1402  break;
1403 
1405  AlterSubscriptionOwner_oid(sdepForm->objid, newrole);
1406  break;
1407 
1408  /* Generic alter owner cases */
1409  case CollationRelationId:
1410  case ConversionRelationId:
1411  case OperatorRelationId:
1412  case ProcedureRelationId:
1413  case LanguageRelationId:
1414  case LargeObjectRelationId:
1417  case ExtensionRelationId:
1418  case TableSpaceRelationId:
1419  case DatabaseRelationId:
1420  case TSConfigRelationId:
1422  {
1423  Oid classId = sdepForm->classid;
1424  Relation catalog;
1425 
1426  if (classId == LargeObjectRelationId)
1428 
1429  catalog = heap_open(classId, RowExclusiveLock);
1430 
1431  AlterObjectOwner_internal(catalog, sdepForm->objid,
1432  newrole);
1433 
1434  heap_close(catalog, NoLock);
1435  }
1436  break;
1437 
1438  default:
1439  elog(ERROR, "unexpected classid %u", sdepForm->classid);
1440  break;
1441  }
1442  /* Make sure the next iteration will see my changes */
1444  }
1445 
1446  systable_endscan(scan);
1447  }
1448 
1449  heap_close(sdepRel, RowExclusiveLock);
1450 }
#define NamespaceRelationId
Definition: pg_namespace.h:34
#define OperatorRelationId
Definition: pg_operator.h:32
#define Anum_pg_shdepend_refclassid
Definition: pg_shdepend.h:75
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
void AlterForeignDataWrapperOwner_oid(Oid fwdId, Oid newOwnerId)
Definition: foreigncmds.c:312
static bool isSharedObjectPinned(Oid classId, Oid objectId, Relation sdepRel)
Definition: pg_shdepend.c:1110
#define SharedDependRelationId
Definition: pg_shdepend.h:29
void AlterSchemaOwner_oid(Oid oid, Oid newOwnerId)
Definition: schemacmds.c:297
#define ProcedureRelationId
Definition: pg_proc.h:33
FormData_pg_shdepend * Form_pg_shdepend
Definition: pg_shdepend.h:64
#define DatabaseRelationId
Definition: pg_database.h:29
#define RelationRelationId
Definition: pg_class.h:29
void AlterForeignServerOwner_oid(Oid srvId, Oid newOwnerId)
Definition: foreigncmds.c:447
#define OperatorClassRelationId
Definition: pg_opclass.h:49
#define OperatorFamilyRelationId
Definition: pg_opfamily.h:29
int errcode(int sqlerrcode)
Definition: elog.c:575
#define PublicationRelationId
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
#define TypeRelationId
Definition: pg_type.h:34
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
#define DefaultAclRelationId
char * getObjectDescription(const ObjectAddress *object)
#define AuthIdRelationId
Definition: pg_authid.h:42
#define TSConfigRelationId
Definition: pg_ts_config.h:31
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define Anum_pg_shdepend_refobjid
Definition: pg_shdepend.h:76
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define TSDictionaryRelationId
Definition: pg_ts_dict.h:31
void AlterTypeOwner_oid(Oid typeOid, Oid newOwnerId, bool hasDependEntry)
Definition: typecmds.c:3321
#define SubscriptionRelationId
void AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
Definition: alter.c:843
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel, rest)
Definition: elog.h:122
void ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing, LOCKMODE lockmode)
Definition: tablecmds.c:9465
void CommandCounterIncrement(void)
Definition: xact.c:921
Oid MyDatabaseId
Definition: globals.c:76
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
#define CollationRelationId
Definition: pg_collation.h:30
#define InvalidOid
Definition: postgres_ext.h:36
void AlterEventTriggerOwner_oid(Oid trigOid, Oid newOwnerId)
#define ForeignServerRelationId
#define NULL
Definition: c.h:226
#define EventTriggerRelationId
#define LargeObjectMetadataRelationId
#define ForeignDataWrapperRelationId
#define TableSpaceRelationId
Definition: pg_tablespace.h:29
#define AccessExclusiveLock
Definition: lockdefs.h:46
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define UserMappingRelationId
void AlterSubscriptionOwner_oid(Oid subid, Oid newOwnerId)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define LanguageRelationId
Definition: pg_language.h:29
void AlterPublicationOwner_oid(Oid subid, Oid newOwnerId)
#define elog
Definition: elog.h:219
#define SharedDependReferenceIndexId
Definition: indexing.h:224
#define ExtensionRelationId
Definition: pg_extension.h:29
#define LargeObjectRelationId
#define ConversionRelationId
Definition: pg_conversion.h:38
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define lfirst_oid(lc)
Definition: pg_list.h:108
void updateAclDependencies ( Oid  classId,
Oid  objectId,
int32  objectSubId,
Oid  ownerId,
int  noldmembers,
Oid oldmembers,
int  nnewmembers,
Oid newmembers 
)

Definition at line 420 of file pg_shdepend.c.

References AuthIdRelationId, getOidListDiff(), heap_close, heap_open(), i, isSharedObjectPinned(), pfree(), RowExclusiveLock, SHARED_DEPENDENCY_ACL, SharedDependRelationId, shdepAddDependency(), and shdepDropDependency().

Referenced by ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), heap_create_with_catalog(), ProcedureCreate(), and SetDefaultACL().

424 {
425  Relation sdepRel;
426  int i;
427 
428  /*
429  * Remove entries that are common to both lists; those represent existing
430  * dependencies we don't need to change.
431  *
432  * OK to overwrite the inputs since we'll pfree them anyway.
433  */
434  getOidListDiff(oldmembers, &noldmembers, newmembers, &nnewmembers);
435 
436  if (noldmembers > 0 || nnewmembers > 0)
437  {
439 
440  /* Add new dependencies that weren't already present */
441  for (i = 0; i < nnewmembers; i++)
442  {
443  Oid roleid = newmembers[i];
444 
445  /*
446  * Skip the owner: he has an OWNER shdep entry instead. (This is
447  * not just a space optimization; it makes ALTER OWNER easier. See
448  * notes in changeDependencyOnOwner.)
449  */
450  if (roleid == ownerId)
451  continue;
452 
453  /* Skip pinned roles; they don't need dependency entries */
454  if (isSharedObjectPinned(AuthIdRelationId, roleid, sdepRel))
455  continue;
456 
457  shdepAddDependency(sdepRel, classId, objectId, objsubId,
458  AuthIdRelationId, roleid,
460  }
461 
462  /* Drop no-longer-used old dependencies */
463  for (i = 0; i < noldmembers; i++)
464  {
465  Oid roleid = oldmembers[i];
466 
467  /* Skip the owner, same as above */
468  if (roleid == ownerId)
469  continue;
470 
471  /* Skip pinned roles */
472  if (isSharedObjectPinned(AuthIdRelationId, roleid, sdepRel))
473  continue;
474 
475  shdepDropDependency(sdepRel, classId, objectId, objsubId,
476  false, /* exact match on objsubId */
477  AuthIdRelationId, roleid,
479  }
480 
481  heap_close(sdepRel, RowExclusiveLock);
482  }
483 
484  if (oldmembers)
485  pfree(oldmembers);
486  if (newmembers)
487  pfree(newmembers);
488 }
static bool isSharedObjectPinned(Oid classId, Oid objectId, Relation sdepRel)
Definition: pg_shdepend.c:1110
#define SharedDependRelationId
Definition: pg_shdepend.h:29
static void getOidListDiff(Oid *list1, int *nlist1, Oid *list2, int *nlist2)
Definition: pg_shdepend.c:350
static void shdepAddDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
Definition: pg_shdepend.c:844
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
#define AuthIdRelationId
Definition: pg_authid.h:42
void pfree(void *pointer)
Definition: mcxt.c:992
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
static void shdepDropDependency(Relation sdepRel, Oid classId, Oid objectId, int32 objsubId, bool drop_subobjects, Oid refclassId, Oid refobjId, SharedDependencyType deptype)
Definition: pg_shdepend.c:899
int i