2002-07-12 20:43:19 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* dependency.h
|
|
|
|
* Routines to support inter-object dependencies.
|
|
|
|
*
|
|
|
|
*
|
2004-12-31 23:04:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
2002-07-12 20:43:19 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2006-02-11 23:17:19 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/catalog/dependency.h,v 1.19 2006/02/11 22:17:19 momjian Exp $
|
2002-07-12 20:43:19 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef DEPENDENCY_H
|
|
|
|
#define DEPENDENCY_H
|
|
|
|
|
|
|
|
#include "nodes/parsenodes.h" /* for DropBehavior */
|
|
|
|
|
|
|
|
|
2004-05-05 06:48:48 +02:00
|
|
|
/*----------
|
2002-07-12 20:43:19 +02:00
|
|
|
* Precise semantics of a dependency relationship are specified by the
|
|
|
|
* DependencyType code (which is stored in a "char" field in pg_depend,
|
|
|
|
* so we assign ASCII-code values to the enumeration members).
|
|
|
|
*
|
|
|
|
* In all cases, a dependency relationship indicates that the referenced
|
|
|
|
* object may not be dropped without also dropping the dependent object.
|
|
|
|
* However, there are several subflavors:
|
|
|
|
*
|
|
|
|
* DEPENDENCY_NORMAL ('n'): normal relationship between separately-created
|
|
|
|
* objects. The dependent object may be dropped without affecting the
|
|
|
|
* referenced object. The referenced object may only be dropped by
|
|
|
|
* specifying CASCADE, in which case the dependent object is dropped too.
|
|
|
|
* Example: a table column has a normal dependency on its datatype.
|
|
|
|
*
|
|
|
|
* DEPENDENCY_AUTO ('a'): the dependent object can be dropped separately
|
|
|
|
* from the referenced object, and should be automatically dropped
|
|
|
|
* (regardless of RESTRICT or CASCADE mode) if the referenced object
|
|
|
|
* is dropped.
|
|
|
|
* Example: a named constraint on a table is made auto-dependent on
|
|
|
|
* the table, so that it will go away if the table is dropped.
|
|
|
|
*
|
|
|
|
* DEPENDENCY_INTERNAL ('i'): the dependent object was created as part
|
|
|
|
* of creation of the referenced object, and is really just a part of
|
|
|
|
* its internal implementation. A DROP of the dependent object will be
|
|
|
|
* disallowed outright (we'll tell the user to issue a DROP against the
|
|
|
|
* referenced object, instead). A DROP of the referenced object will be
|
|
|
|
* propagated through to drop the dependent object whether CASCADE is
|
|
|
|
* specified or not.
|
|
|
|
* Example: a trigger that's created to enforce a foreign-key constraint
|
|
|
|
* is made internally dependent on the constraint's pg_constraint entry.
|
|
|
|
*
|
|
|
|
* DEPENDENCY_PIN ('p'): there is no dependent object; this type of entry
|
|
|
|
* is a signal that the system itself depends on the referenced object,
|
|
|
|
* and so that object must never be deleted. Entries of this type are
|
2002-09-04 22:31:48 +02:00
|
|
|
* created only during initdb. The fields for the dependent object
|
2002-07-12 20:43:19 +02:00
|
|
|
* contain zeroes.
|
|
|
|
*
|
|
|
|
* Other dependency flavors may be needed in future.
|
2004-05-05 06:48:48 +02:00
|
|
|
*----------
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum DependencyType
|
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
DEPENDENCY_NORMAL = 'n',
|
|
|
|
DEPENDENCY_AUTO = 'a',
|
|
|
|
DEPENDENCY_INTERNAL = 'i',
|
|
|
|
DEPENDENCY_PIN = 'p'
|
2002-07-12 20:43:19 +02:00
|
|
|
} DependencyType;
|
|
|
|
|
2005-07-07 22:40:02 +02:00
|
|
|
/*
|
|
|
|
* There is also a SharedDependencyType enum type that determines the exact
|
|
|
|
* semantics of an entry in pg_shdepend. Just like regular dependency entries,
|
|
|
|
* any pg_shdepend entry means that the referenced object cannot be dropped
|
|
|
|
* unless the dependent object is dropped at the same time. There are some
|
|
|
|
* additional rules however:
|
|
|
|
*
|
|
|
|
* (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object --
|
|
|
|
* rather, the referenced object is an essential part of the system. This
|
|
|
|
* applies to the initdb-created superuser. Entries of this type are only
|
|
|
|
* created by initdb; objects in this category don't need further pg_shdepend
|
|
|
|
* entries if more objects come to depend on them.
|
|
|
|
*
|
|
|
|
* (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is
|
|
|
|
* the role owning the dependent object. The referenced object must be
|
|
|
|
* a pg_authid entry.
|
|
|
|
*
|
|
|
|
* (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is
|
|
|
|
* a role mentioned in the ACL field of the dependent object. The referenced
|
|
|
|
* object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not
|
|
|
|
* created for the owner of an object; hence two objects may be linked by
|
|
|
|
* one or the other, but not both, of these dependency types.)
|
|
|
|
*
|
|
|
|
* SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
|
|
|
|
* routines, and is not valid in the catalog itself.
|
|
|
|
*/
|
|
|
|
typedef enum SharedDependencyType
|
|
|
|
{
|
|
|
|
SHARED_DEPENDENCY_PIN = 'p',
|
|
|
|
SHARED_DEPENDENCY_OWNER = 'o',
|
|
|
|
SHARED_DEPENDENCY_ACL = 'a',
|
|
|
|
SHARED_DEPENDENCY_INVALID = 0
|
|
|
|
} SharedDependencyType;
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The two objects related by a dependency are identified by ObjectAddresses.
|
|
|
|
*/
|
|
|
|
typedef struct ObjectAddress
|
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid classId; /* Class Id from pg_class */
|
|
|
|
Oid objectId; /* OID of the object */
|
2005-10-15 04:49:52 +02:00
|
|
|
int32 objectSubId; /* Subitem within the object (column of table) */
|
2002-07-12 20:43:19 +02:00
|
|
|
} ObjectAddress;
|
|
|
|
|
|
|
|
|
2004-05-05 06:48:48 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* This enum covers all system catalogs whose OIDs can appear in
|
2005-07-07 22:40:02 +02:00
|
|
|
* pg_depend.classId or pg_shdepend.classId.
|
2004-05-05 06:48:48 +02:00
|
|
|
*/
|
|
|
|
typedef enum ObjectClass
|
|
|
|
{
|
|
|
|
OCLASS_CLASS, /* pg_class */
|
|
|
|
OCLASS_PROC, /* pg_proc */
|
|
|
|
OCLASS_TYPE, /* pg_type */
|
|
|
|
OCLASS_CAST, /* pg_cast */
|
|
|
|
OCLASS_CONSTRAINT, /* pg_constraint */
|
|
|
|
OCLASS_CONVERSION, /* pg_conversion */
|
|
|
|
OCLASS_DEFAULT, /* pg_attrdef */
|
|
|
|
OCLASS_LANGUAGE, /* pg_language */
|
|
|
|
OCLASS_OPERATOR, /* pg_operator */
|
|
|
|
OCLASS_OPCLASS, /* pg_opclass */
|
|
|
|
OCLASS_REWRITE, /* pg_rewrite */
|
|
|
|
OCLASS_TRIGGER, /* pg_trigger */
|
|
|
|
OCLASS_SCHEMA, /* pg_namespace */
|
2005-07-07 22:40:02 +02:00
|
|
|
OCLASS_ROLE, /* pg_authid */
|
|
|
|
OCLASS_DATABASE, /* pg_database */
|
|
|
|
OCLASS_TBLSPACE, /* pg_tablespace */
|
2004-05-05 06:48:48 +02:00
|
|
|
MAX_OCLASS /* MUST BE LAST */
|
|
|
|
} ObjectClass;
|
|
|
|
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/* in dependency.c */
|
|
|
|
|
|
|
|
extern void performDeletion(const ObjectAddress *object,
|
2002-09-04 22:31:48 +02:00
|
|
|
DropBehavior behavior);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2003-03-06 23:54:49 +01:00
|
|
|
extern void deleteWhatDependsOn(const ObjectAddress *object,
|
2003-08-04 02:43:34 +02:00
|
|
|
bool showNotices);
|
2003-02-07 02:33:06 +01:00
|
|
|
|
2002-07-16 07:53:34 +02:00
|
|
|
extern void recordDependencyOnExpr(const ObjectAddress *depender,
|
2002-09-04 22:31:48 +02:00
|
|
|
Node *expr, List *rtable,
|
|
|
|
DependencyType behavior);
|
2002-07-16 07:53:34 +02:00
|
|
|
|
2003-05-28 18:04:02 +02:00
|
|
|
extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
|
2003-08-04 02:43:34 +02:00
|
|
|
Node *expr, Oid relId,
|
|
|
|
DependencyType behavior,
|
|
|
|
DependencyType self_behavior);
|
2003-05-28 18:04:02 +02:00
|
|
|
|
2004-05-05 06:48:48 +02:00
|
|
|
extern ObjectClass getObjectClass(const ObjectAddress *object);
|
|
|
|
|
|
|
|
extern char *getObjectDescription(const ObjectAddress *object);
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/* in pg_depend.c */
|
|
|
|
|
|
|
|
extern void recordDependencyOn(const ObjectAddress *depender,
|
2002-09-04 22:31:48 +02:00
|
|
|
const ObjectAddress *referenced,
|
|
|
|
DependencyType behavior);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2002-07-16 07:53:34 +02:00
|
|
|
extern void recordMultipleDependencies(const ObjectAddress *depender,
|
2002-09-04 22:31:48 +02:00
|
|
|
const ObjectAddress *referenced,
|
|
|
|
int nreferenced,
|
|
|
|
DependencyType behavior);
|
2002-07-16 07:53:34 +02:00
|
|
|
|
2002-08-11 23:17:35 +02:00
|
|
|
extern long deleteDependencyRecordsFor(Oid classId, Oid objectId);
|
2002-07-17 00:12:20 +02:00
|
|
|
|
2005-08-01 06:03:59 +02:00
|
|
|
extern long changeDependencyFor(Oid classId, Oid objectId,
|
2005-10-15 04:49:52 +02:00
|
|
|
Oid refClassId, Oid oldRefObjectId,
|
|
|
|
Oid newRefObjectId);
|
2005-08-01 06:03:59 +02:00
|
|
|
|
2005-11-21 13:49:33 +01:00
|
|
|
extern bool objectIsInternalDependency(Oid classId, Oid objectId);
|
|
|
|
|
2006-02-11 23:17:19 +01:00
|
|
|
extern List* getDependentOids(Oid classId, Oid objId,
|
|
|
|
Oid refClassId, DependencyType deptype);
|
|
|
|
|
|
|
|
extern List* getReferencingOids(Oid refClassId, Oid refObjId, Oid refObjSubId,
|
|
|
|
Oid classId, DependencyType deptype);
|
|
|
|
|
2005-07-07 22:40:02 +02:00
|
|
|
/* in pg_shdepend.c */
|
|
|
|
|
|
|
|
extern void recordSharedDependencyOn(ObjectAddress *depender,
|
2005-10-15 04:49:52 +02:00
|
|
|
ObjectAddress *referenced,
|
|
|
|
SharedDependencyType deptype);
|
2005-07-07 22:40:02 +02:00
|
|
|
|
|
|
|
extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId);
|
|
|
|
|
|
|
|
extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
|
|
|
|
|
|
|
|
extern void changeDependencyOnOwner(Oid classId, Oid objectId,
|
2005-10-15 04:49:52 +02:00
|
|
|
Oid newOwnerId);
|
2005-07-07 22:40:02 +02:00
|
|
|
|
|
|
|
extern void updateAclDependencies(Oid classId, Oid objectId,
|
2005-10-15 04:49:52 +02:00
|
|
|
Oid ownerId, bool isGrant,
|
|
|
|
int noldmembers, Oid *oldmembers,
|
|
|
|
int nnewmembers, Oid *newmembers);
|
2005-07-07 22:40:02 +02:00
|
|
|
|
|
|
|
extern char *checkSharedDependencies(Oid classId, Oid objectId);
|
|
|
|
|
|
|
|
extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
|
|
|
|
|
|
|
|
extern void dropDatabaseDependencies(Oid databaseId);
|
|
|
|
|
2005-11-21 13:49:33 +01:00
|
|
|
extern void shdepDropOwned(List *relids, DropBehavior behavior);
|
|
|
|
|
|
|
|
extern void shdepReassignOwned(List *relids, Oid newrole);
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
#endif /* DEPENDENCY_H */
|