PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
dependency.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * dependency.h
4  * Routines to support inter-object dependencies.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/catalog/dependency.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef DEPENDENCY_H
15 #define DEPENDENCY_H
16 
17 #include "catalog/objectaddress.h"
18 
19 
20 /*
21  * Precise semantics of a dependency relationship are specified by the
22  * DependencyType code (which is stored in a "char" field in pg_depend,
23  * so we assign ASCII-code values to the enumeration members).
24  *
25  * In all cases, a dependency relationship indicates that the referenced
26  * object may not be dropped without also dropping the dependent object.
27  * However, there are several subflavors:
28  *
29  * DEPENDENCY_NORMAL ('n'): normal relationship between separately-created
30  * objects. The dependent object may be dropped without affecting the
31  * referenced object. The referenced object may only be dropped by
32  * specifying CASCADE, in which case the dependent object is dropped too.
33  * Example: a table column has a normal dependency on its datatype.
34  *
35  * DEPENDENCY_AUTO ('a'): the dependent object can be dropped separately
36  * from the referenced object, and should be automatically dropped
37  * (regardless of RESTRICT or CASCADE mode) if the referenced object
38  * is dropped.
39  * Example: a named constraint on a table is made auto-dependent on
40  * the table, so that it will go away if the table is dropped.
41  *
42  * DEPENDENCY_INTERNAL ('i'): the dependent object was created as part
43  * of creation of the referenced object, and is really just a part of
44  * its internal implementation. A DROP of the dependent object will be
45  * disallowed outright (we'll tell the user to issue a DROP against the
46  * referenced object, instead). A DROP of the referenced object will be
47  * propagated through to drop the dependent object whether CASCADE is
48  * specified or not.
49  * Example: a trigger that's created to enforce a foreign-key constraint
50  * is made internally dependent on the constraint's pg_constraint entry.
51  *
52  * DEPENDENCY_EXTENSION ('e'): the dependent object is a member of the
53  * extension that is the referenced object. The dependent object can be
54  * dropped only via DROP EXTENSION on the referenced object. Functionally
55  * this dependency type acts the same as an internal dependency, but it's
56  * kept separate for clarity and to simplify pg_dump.
57  *
58  * DEPENDENCY_AUTO_EXTENSION ('x'): the dependent object is not a member
59  * of the extension that is the referenced object (and so should not be
60  * ignored by pg_dump), but cannot function without the extension and
61  * should be dropped when the extension itself is. The dependent object
62  * may be dropped on its own as well.
63  *
64  * DEPENDENCY_PIN ('p'): there is no dependent object; this type of entry
65  * is a signal that the system itself depends on the referenced object,
66  * and so that object must never be deleted. Entries of this type are
67  * created only during initdb. The fields for the dependent object
68  * contain zeroes.
69  *
70  * Other dependency flavors may be needed in future.
71  */
72 
73 typedef enum DependencyType
74 {
82 
83 /*
84  * There is also a SharedDependencyType enum type that determines the exact
85  * semantics of an entry in pg_shdepend. Just like regular dependency entries,
86  * any pg_shdepend entry means that the referenced object cannot be dropped
87  * unless the dependent object is dropped at the same time. There are some
88  * additional rules however:
89  *
90  * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object --
91  * rather, the referenced object is an essential part of the system. This
92  * applies to the initdb-created superuser. Entries of this type are only
93  * created by initdb; objects in this category don't need further pg_shdepend
94  * entries if more objects come to depend on them.
95  *
96  * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is
97  * the role owning the dependent object. The referenced object must be
98  * a pg_authid entry.
99  *
100  * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is
101  * a role mentioned in the ACL field of the dependent object. The referenced
102  * object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not
103  * created for the owner of an object; hence two objects may be linked by
104  * one or the other, but not both, of these dependency types.)
105  *
106  * (d) a SHARED_DEPENDENCY_POLICY entry means that the referenced object is
107  * a role mentioned in a policy object. The referenced object must be a
108  * pg_authid entry.
109  *
110  * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
111  * routines, and is not valid in the catalog itself.
112  */
114 {
121 
122 /* expansible list of ObjectAddresses (private in dependency.c) */
124 
125 /*
126  * This enum covers all system catalogs whose OIDs can appear in
127  * pg_depend.classId or pg_shdepend.classId. Keep object_classes[] in sync.
128  */
129 typedef enum ObjectClass
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_STATISTIC_EXT, /* pg_statistic_ext */
151  OCLASS_TSPARSER, /* pg_ts_parser */
152  OCLASS_TSDICT, /* pg_ts_dict */
153  OCLASS_TSTEMPLATE, /* pg_ts_template */
154  OCLASS_TSCONFIG, /* pg_ts_config */
155  OCLASS_ROLE, /* pg_authid */
156  OCLASS_DATABASE, /* pg_database */
157  OCLASS_TBLSPACE, /* pg_tablespace */
158  OCLASS_FDW, /* pg_foreign_data_wrapper */
159  OCLASS_FOREIGN_SERVER, /* pg_foreign_server */
160  OCLASS_USER_MAPPING, /* pg_user_mapping */
161  OCLASS_DEFACL, /* pg_default_acl */
162  OCLASS_EXTENSION, /* pg_extension */
163  OCLASS_EVENT_TRIGGER, /* pg_event_trigger */
164  OCLASS_POLICY, /* pg_policy */
165  OCLASS_PUBLICATION, /* pg_publication */
166  OCLASS_PUBLICATION_REL, /* pg_publication_rel */
167  OCLASS_SUBSCRIPTION, /* pg_subscription */
168  OCLASS_TRANSFORM /* pg_transform */
169 } ObjectClass;
170 
171 #define LAST_OCLASS OCLASS_TRANSFORM
172 
173 /* flag bits for performDeletion/performMultipleDeletions: */
174 #define PERFORM_DELETION_INTERNAL 0x0001 /* internal action */
175 #define PERFORM_DELETION_CONCURRENTLY 0x0002 /* concurrent drop */
176 #define PERFORM_DELETION_QUIETLY 0x0004 /* suppress notices */
177 #define PERFORM_DELETION_SKIP_ORIGINAL 0x0008 /* keep original obj */
178 #define PERFORM_DELETION_SKIP_EXTENSIONS 0x0010 /* keep extensions */
179 
180 
181 /* in dependency.c */
182 
183 extern void performDeletion(const ObjectAddress *object,
184  DropBehavior behavior, int flags);
185 
186 extern void performMultipleDeletions(const ObjectAddresses *objects,
187  DropBehavior behavior, int flags);
188 
189 extern void recordDependencyOnExpr(const ObjectAddress *depender,
190  Node *expr, List *rtable,
191  DependencyType behavior);
192 
193 extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
194  Node *expr, Oid relId,
195  DependencyType behavior,
196  DependencyType self_behavior,
197  bool ignore_self);
198 
199 extern ObjectClass getObjectClass(const ObjectAddress *object);
200 
202 
203 extern void add_exact_object_address(const ObjectAddress *object,
204  ObjectAddresses *addrs);
205 
206 extern bool object_address_present(const ObjectAddress *object,
207  const ObjectAddresses *addrs);
208 
209 extern void record_object_address_dependencies(const ObjectAddress *depender,
210  ObjectAddresses *referenced,
211  DependencyType behavior);
212 
213 extern void free_object_addresses(ObjectAddresses *addrs);
214 
215 /* in pg_depend.c */
216 
217 extern void recordDependencyOn(const ObjectAddress *depender,
218  const ObjectAddress *referenced,
219  DependencyType behavior);
220 
221 extern void recordMultipleDependencies(const ObjectAddress *depender,
222  const ObjectAddress *referenced,
223  int nreferenced,
224  DependencyType behavior);
225 
226 extern void recordDependencyOnCurrentExtension(const ObjectAddress *object,
227  bool isReplace);
228 
229 extern long deleteDependencyRecordsFor(Oid classId, Oid objectId,
230  bool skipExtensionDeps);
231 
232 extern long deleteDependencyRecordsForClass(Oid classId, Oid objectId,
233  Oid refclassId, char deptype);
234 
235 extern long changeDependencyFor(Oid classId, Oid objectId,
236  Oid refClassId, Oid oldRefObjectId,
237  Oid newRefObjectId);
238 
239 extern Oid getExtensionOfObject(Oid classId, Oid objectId);
240 
241 extern bool sequenceIsOwned(Oid seqId, Oid *tableId, int32 *colId);
242 
243 extern void markSequenceUnowned(Oid seqId);
244 
245 extern List *getOwnedSequences(Oid relid);
246 
247 extern Oid get_constraint_index(Oid constraintId);
248 
249 extern Oid get_index_constraint(Oid indexId);
250 
251 /* in pg_shdepend.c */
252 
253 extern void recordSharedDependencyOn(ObjectAddress *depender,
254  ObjectAddress *referenced,
255  SharedDependencyType deptype);
256 
257 extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId,
258  int32 objectSubId);
259 
260 extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
261 
262 extern void changeDependencyOnOwner(Oid classId, Oid objectId,
263  Oid newOwnerId);
264 
265 extern void updateAclDependencies(Oid classId, Oid objectId, int32 objectSubId,
266  Oid ownerId,
267  int noldmembers, Oid *oldmembers,
268  int nnewmembers, Oid *newmembers);
269 
270 extern bool checkSharedDependencies(Oid classId, Oid objectId,
271  char **detail_msg, char **detail_log_msg);
272 
273 extern void shdepLockAndCheckObject(Oid classId, Oid objectId);
274 
275 extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
276 
277 extern void dropDatabaseDependencies(Oid databaseId);
278 
279 extern void shdepDropOwned(List *relids, DropBehavior behavior);
280 
281 extern void shdepReassignOwned(List *relids, Oid newrole);
282 
283 #endif /* DEPENDENCY_H */
List * getOwnedSequences(Oid relid)
Definition: pg_depend.c:560
DependencyType
Definition: dependency.h:73
void updateAclDependencies(Oid classId, Oid objectId, int32 objectSubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
Definition: pg_shdepend.c:421
bool sequenceIsOwned(Oid seqId, Oid *tableId, int32 *colId)
Definition: pg_depend.c:500
void shdepLockAndCheckObject(Oid classId, Oid objectId)
Definition: pg_shdepend.c:987
void shdepReassignOwned(List *relids, Oid newrole)
Definition: pg_shdepend.c:1285
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
Definition: pg_shdepend.c:522
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
Definition: dependency.c:303
Definition: nodes.h:506
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
Definition: pg_depend.c:241
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:56
unsigned int Oid
Definition: postgres_ext.h:31
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:304
void dropDatabaseDependencies(Oid databaseId)
Definition: pg_shdepend.c:775
signed int int32
Definition: c.h:256
void copyTemplateDependencies(Oid templateDbId, Oid newDbId)
Definition: pg_shdepend.c:711
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:295
ObjectClass
Definition: dependency.h:129
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:823
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2318
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2303
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:159
SharedDependencyType
Definition: dependency.h:113
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
Definition: dependency.c:2147
DropBehavior
Definition: parsenodes.h:1628
Oid get_index_constraint(Oid indexId)
Definition: pg_depend.c:676
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Definition: pg_depend.c:191
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2087
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2032
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
Definition: dependency.c:362
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:447
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:139
Oid get_constraint_index(Oid constraintId)
Definition: pg_depend.c:618
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1338
void recordSharedDependencyOn(ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
Definition: pg_shdepend.c:115
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool ignore_self)
Definition: dependency.c:1379
Definition: pg_list.h:45
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2289
void shdepDropOwned(List *relids, DropBehavior behavior)
Definition: pg_shdepend.c:1163
void markSequenceUnowned(Oid seqId)
Definition: pg_depend.c:550