Header And Logo

PostgreSQL
| The world's most advanced open source database.

dependency.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * dependency.h
00004  *    Routines to support inter-object dependencies.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/catalog/dependency.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef DEPENDENCY_H
00015 #define DEPENDENCY_H
00016 
00017 #include "catalog/objectaddress.h"
00018 
00019 
00020 /*
00021  * Precise semantics of a dependency relationship are specified by the
00022  * DependencyType code (which is stored in a "char" field in pg_depend,
00023  * so we assign ASCII-code values to the enumeration members).
00024  *
00025  * In all cases, a dependency relationship indicates that the referenced
00026  * object may not be dropped without also dropping the dependent object.
00027  * However, there are several subflavors:
00028  *
00029  * DEPENDENCY_NORMAL ('n'): normal relationship between separately-created
00030  * objects.  The dependent object may be dropped without affecting the
00031  * referenced object.  The referenced object may only be dropped by
00032  * specifying CASCADE, in which case the dependent object is dropped too.
00033  * Example: a table column has a normal dependency on its datatype.
00034  *
00035  * DEPENDENCY_AUTO ('a'): the dependent object can be dropped separately
00036  * from the referenced object, and should be automatically dropped
00037  * (regardless of RESTRICT or CASCADE mode) if the referenced object
00038  * is dropped.
00039  * Example: a named constraint on a table is made auto-dependent on
00040  * the table, so that it will go away if the table is dropped.
00041  *
00042  * DEPENDENCY_INTERNAL ('i'): the dependent object was created as part
00043  * of creation of the referenced object, and is really just a part of
00044  * its internal implementation.  A DROP of the dependent object will be
00045  * disallowed outright (we'll tell the user to issue a DROP against the
00046  * referenced object, instead).  A DROP of the referenced object will be
00047  * propagated through to drop the dependent object whether CASCADE is
00048  * specified or not.
00049  * Example: a trigger that's created to enforce a foreign-key constraint
00050  * is made internally dependent on the constraint's pg_constraint entry.
00051  *
00052  * DEPENDENCY_EXTENSION ('e'): the dependent object is a member of the
00053  * extension that is the referenced object.  The dependent object can be
00054  * dropped only via DROP EXTENSION on the referenced object.  Functionally
00055  * this dependency type acts the same as an internal dependency, but it's
00056  * kept separate for clarity and to simplify pg_dump.
00057  *
00058  * DEPENDENCY_PIN ('p'): there is no dependent object; this type of entry
00059  * is a signal that the system itself depends on the referenced object,
00060  * and so that object must never be deleted.  Entries of this type are
00061  * created only during initdb.  The fields for the dependent object
00062  * contain zeroes.
00063  *
00064  * Other dependency flavors may be needed in future.
00065  */
00066 
00067 typedef enum DependencyType
00068 {
00069     DEPENDENCY_NORMAL = 'n',
00070     DEPENDENCY_AUTO = 'a',
00071     DEPENDENCY_INTERNAL = 'i',
00072     DEPENDENCY_EXTENSION = 'e',
00073     DEPENDENCY_PIN = 'p'
00074 } DependencyType;
00075 
00076 /*
00077  * There is also a SharedDependencyType enum type that determines the exact
00078  * semantics of an entry in pg_shdepend.  Just like regular dependency entries,
00079  * any pg_shdepend entry means that the referenced object cannot be dropped
00080  * unless the dependent object is dropped at the same time.  There are some
00081  * additional rules however:
00082  *
00083  * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object --
00084  * rather, the referenced object is an essential part of the system.  This
00085  * applies to the initdb-created superuser.  Entries of this type are only
00086  * created by initdb; objects in this category don't need further pg_shdepend
00087  * entries if more objects come to depend on them.
00088  *
00089  * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is
00090  * the role owning the dependent object.  The referenced object must be
00091  * a pg_authid entry.
00092  *
00093  * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is
00094  * a role mentioned in the ACL field of the dependent object.  The referenced
00095  * object must be a pg_authid entry.  (SHARED_DEPENDENCY_ACL entries are not
00096  * created for the owner of an object; hence two objects may be linked by
00097  * one or the other, but not both, of these dependency types.)
00098  *
00099  * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
00100  * routines, and is not valid in the catalog itself.
00101  */
00102 typedef enum SharedDependencyType
00103 {
00104     SHARED_DEPENDENCY_PIN = 'p',
00105     SHARED_DEPENDENCY_OWNER = 'o',
00106     SHARED_DEPENDENCY_ACL = 'a',
00107     SHARED_DEPENDENCY_INVALID = 0
00108 } SharedDependencyType;
00109 
00110 /* expansible list of ObjectAddresses (private in dependency.c) */
00111 typedef struct ObjectAddresses ObjectAddresses;
00112 
00113 /*
00114  * This enum covers all system catalogs whose OIDs can appear in
00115  * pg_depend.classId or pg_shdepend.classId.
00116  */
00117 typedef enum ObjectClass
00118 {
00119     OCLASS_CLASS,               /* pg_class */
00120     OCLASS_PROC,                /* pg_proc */
00121     OCLASS_TYPE,                /* pg_type */
00122     OCLASS_CAST,                /* pg_cast */
00123     OCLASS_COLLATION,           /* pg_collation */
00124     OCLASS_CONSTRAINT,          /* pg_constraint */
00125     OCLASS_CONVERSION,          /* pg_conversion */
00126     OCLASS_DEFAULT,             /* pg_attrdef */
00127     OCLASS_LANGUAGE,            /* pg_language */
00128     OCLASS_LARGEOBJECT,         /* pg_largeobject */
00129     OCLASS_OPERATOR,            /* pg_operator */
00130     OCLASS_OPCLASS,             /* pg_opclass */
00131     OCLASS_OPFAMILY,            /* pg_opfamily */
00132     OCLASS_AMOP,                /* pg_amop */
00133     OCLASS_AMPROC,              /* pg_amproc */
00134     OCLASS_REWRITE,             /* pg_rewrite */
00135     OCLASS_TRIGGER,             /* pg_trigger */
00136     OCLASS_SCHEMA,              /* pg_namespace */
00137     OCLASS_TSPARSER,            /* pg_ts_parser */
00138     OCLASS_TSDICT,              /* pg_ts_dict */
00139     OCLASS_TSTEMPLATE,          /* pg_ts_template */
00140     OCLASS_TSCONFIG,            /* pg_ts_config */
00141     OCLASS_ROLE,                /* pg_authid */
00142     OCLASS_DATABASE,            /* pg_database */
00143     OCLASS_TBLSPACE,            /* pg_tablespace */
00144     OCLASS_FDW,                 /* pg_foreign_data_wrapper */
00145     OCLASS_FOREIGN_SERVER,      /* pg_foreign_server */
00146     OCLASS_USER_MAPPING,        /* pg_user_mapping */
00147     OCLASS_DEFACL,              /* pg_default_acl */
00148     OCLASS_EXTENSION,           /* pg_extension */
00149     OCLASS_EVENT_TRIGGER,       /* pg_event_trigger */
00150     MAX_OCLASS                  /* MUST BE LAST */
00151 } ObjectClass;
00152 
00153 
00154 /* in dependency.c */
00155 
00156 #define PERFORM_DELETION_INTERNAL           0x0001
00157 #define PERFORM_DELETION_CONCURRENTLY       0x0002
00158 
00159 extern void performDeletion(const ObjectAddress *object,
00160                 DropBehavior behavior, int flags);
00161 
00162 extern void performMultipleDeletions(const ObjectAddresses *objects,
00163                          DropBehavior behavior, int flags);
00164 
00165 extern void deleteWhatDependsOn(const ObjectAddress *object,
00166                     bool showNotices);
00167 
00168 extern void recordDependencyOnExpr(const ObjectAddress *depender,
00169                        Node *expr, List *rtable,
00170                        DependencyType behavior);
00171 
00172 extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
00173                                 Node *expr, Oid relId,
00174                                 DependencyType behavior,
00175                                 DependencyType self_behavior);
00176 
00177 extern ObjectClass getObjectClass(const ObjectAddress *object);
00178 
00179 extern ObjectAddresses *new_object_addresses(void);
00180 
00181 extern void add_exact_object_address(const ObjectAddress *object,
00182                          ObjectAddresses *addrs);
00183 
00184 extern bool object_address_present(const ObjectAddress *object,
00185                        const ObjectAddresses *addrs);
00186 
00187 extern void record_object_address_dependencies(const ObjectAddress *depender,
00188                                    ObjectAddresses *referenced,
00189                                    DependencyType behavior);
00190 
00191 extern void free_object_addresses(ObjectAddresses *addrs);
00192 
00193 /* in pg_depend.c */
00194 
00195 extern void recordDependencyOn(const ObjectAddress *depender,
00196                    const ObjectAddress *referenced,
00197                    DependencyType behavior);
00198 
00199 extern void recordMultipleDependencies(const ObjectAddress *depender,
00200                            const ObjectAddress *referenced,
00201                            int nreferenced,
00202                            DependencyType behavior);
00203 
00204 extern void recordDependencyOnCurrentExtension(const ObjectAddress *object,
00205                                    bool isReplace);
00206 
00207 extern long deleteDependencyRecordsFor(Oid classId, Oid objectId,
00208                            bool skipExtensionDeps);
00209 
00210 extern long deleteDependencyRecordsForClass(Oid classId, Oid objectId,
00211                                 Oid refclassId, char deptype);
00212 
00213 extern long changeDependencyFor(Oid classId, Oid objectId,
00214                     Oid refClassId, Oid oldRefObjectId,
00215                     Oid newRefObjectId);
00216 
00217 extern Oid  getExtensionOfObject(Oid classId, Oid objectId);
00218 
00219 extern bool sequenceIsOwned(Oid seqId, Oid *tableId, int32 *colId);
00220 
00221 extern void markSequenceUnowned(Oid seqId);
00222 
00223 extern List *getOwnedSequences(Oid relid);
00224 
00225 extern Oid  get_constraint_index(Oid constraintId);
00226 
00227 extern Oid  get_index_constraint(Oid indexId);
00228 
00229 /* in pg_shdepend.c */
00230 
00231 extern void recordSharedDependencyOn(ObjectAddress *depender,
00232                          ObjectAddress *referenced,
00233                          SharedDependencyType deptype);
00234 
00235 extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId,
00236                                  int32 objectSubId);
00237 
00238 extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
00239 
00240 extern void changeDependencyOnOwner(Oid classId, Oid objectId,
00241                         Oid newOwnerId);
00242 
00243 extern void updateAclDependencies(Oid classId, Oid objectId, int32 objectSubId,
00244                       Oid ownerId,
00245                       int noldmembers, Oid *oldmembers,
00246                       int nnewmembers, Oid *newmembers);
00247 
00248 extern bool checkSharedDependencies(Oid classId, Oid objectId,
00249                         char **detail_msg, char **detail_log_msg);
00250 
00251 extern void shdepLockAndCheckObject(Oid classId, Oid objectId);
00252 
00253 extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
00254 
00255 extern void dropDatabaseDependencies(Oid databaseId);
00256 
00257 extern void shdepDropOwned(List *relids, DropBehavior behavior);
00258 
00259 extern void shdepReassignOwned(List *relids, Oid newrole);
00260 
00261 #endif   /* DEPENDENCY_H */