PostgreSQL Source Code  git master
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-2019, 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; see the description of pg_depend
28  * in catalogs.sgml for details.
29  */
30 
31 typedef enum DependencyType
32 {
42 
43 /*
44  * There is also a SharedDependencyType enum type that determines the exact
45  * semantics of an entry in pg_shdepend. Just like regular dependency entries,
46  * any pg_shdepend entry means that the referenced object cannot be dropped
47  * unless the dependent object is dropped at the same time. There are some
48  * additional rules however:
49  *
50  * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object --
51  * rather, the referenced object is an essential part of the system. This
52  * applies to the initdb-created superuser. Entries of this type are only
53  * created by initdb; objects in this category don't need further pg_shdepend
54  * entries if more objects come to depend on them.
55  *
56  * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is
57  * the role owning the dependent object. The referenced object must be
58  * a pg_authid entry.
59  *
60  * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is
61  * a role mentioned in the ACL field of the dependent object. The referenced
62  * object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not
63  * created for the owner of an object; hence two objects may be linked by
64  * one or the other, but not both, of these dependency types.)
65  *
66  * (d) a SHARED_DEPENDENCY_POLICY entry means that the referenced object is
67  * a role mentioned in a policy object. The referenced object must be a
68  * pg_authid entry.
69  *
70  * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
71  * routines, and is not valid in the catalog itself.
72  */
74 {
81 
82 /* expansible list of ObjectAddresses (private in dependency.c) */
84 
85 /*
86  * This enum covers all system catalogs whose OIDs can appear in
87  * pg_depend.classId or pg_shdepend.classId. Keep object_classes[] in sync.
88  */
89 typedef enum ObjectClass
90 {
91  OCLASS_CLASS, /* pg_class */
92  OCLASS_PROC, /* pg_proc */
93  OCLASS_TYPE, /* pg_type */
94  OCLASS_CAST, /* pg_cast */
95  OCLASS_COLLATION, /* pg_collation */
96  OCLASS_CONSTRAINT, /* pg_constraint */
97  OCLASS_CONVERSION, /* pg_conversion */
98  OCLASS_DEFAULT, /* pg_attrdef */
99  OCLASS_LANGUAGE, /* pg_language */
100  OCLASS_LARGEOBJECT, /* pg_largeobject */
101  OCLASS_OPERATOR, /* pg_operator */
102  OCLASS_OPCLASS, /* pg_opclass */
103  OCLASS_OPFAMILY, /* pg_opfamily */
104  OCLASS_AM, /* pg_am */
105  OCLASS_AMOP, /* pg_amop */
106  OCLASS_AMPROC, /* pg_amproc */
107  OCLASS_REWRITE, /* pg_rewrite */
108  OCLASS_TRIGGER, /* pg_trigger */
109  OCLASS_SCHEMA, /* pg_namespace */
110  OCLASS_STATISTIC_EXT, /* pg_statistic_ext */
111  OCLASS_TSPARSER, /* pg_ts_parser */
112  OCLASS_TSDICT, /* pg_ts_dict */
113  OCLASS_TSTEMPLATE, /* pg_ts_template */
114  OCLASS_TSCONFIG, /* pg_ts_config */
115  OCLASS_ROLE, /* pg_authid */
116  OCLASS_DATABASE, /* pg_database */
117  OCLASS_TBLSPACE, /* pg_tablespace */
118  OCLASS_FDW, /* pg_foreign_data_wrapper */
119  OCLASS_FOREIGN_SERVER, /* pg_foreign_server */
120  OCLASS_USER_MAPPING, /* pg_user_mapping */
121  OCLASS_DEFACL, /* pg_default_acl */
122  OCLASS_EXTENSION, /* pg_extension */
123  OCLASS_EVENT_TRIGGER, /* pg_event_trigger */
124  OCLASS_POLICY, /* pg_policy */
125  OCLASS_PUBLICATION, /* pg_publication */
126  OCLASS_PUBLICATION_REL, /* pg_publication_rel */
127  OCLASS_SUBSCRIPTION, /* pg_subscription */
128  OCLASS_TRANSFORM /* pg_transform */
129 } ObjectClass;
130 
131 #define LAST_OCLASS OCLASS_TRANSFORM
132 
133 /* flag bits for performDeletion/performMultipleDeletions: */
134 #define PERFORM_DELETION_INTERNAL 0x0001 /* internal action */
135 #define PERFORM_DELETION_CONCURRENTLY 0x0002 /* concurrent drop */
136 #define PERFORM_DELETION_QUIETLY 0x0004 /* suppress notices */
137 #define PERFORM_DELETION_SKIP_ORIGINAL 0x0008 /* keep original obj */
138 #define PERFORM_DELETION_SKIP_EXTENSIONS 0x0010 /* keep extensions */
139 #define PERFORM_DELETION_CONCURRENT_LOCK 0x0020 /* normal drop with
140  * concurrent lock mode */
141 
142 
143 /* in dependency.c */
144 
145 extern void performDeletion(const ObjectAddress *object,
146  DropBehavior behavior, int flags);
147 
148 extern void performMultipleDeletions(const ObjectAddresses *objects,
149  DropBehavior behavior, int flags);
150 
151 extern void recordDependencyOnExpr(const ObjectAddress *depender,
152  Node *expr, List *rtable,
153  DependencyType behavior);
154 
155 extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
156  Node *expr, Oid relId,
157  DependencyType behavior,
158  DependencyType self_behavior,
159  bool reverse_self);
160 
161 extern ObjectClass getObjectClass(const ObjectAddress *object);
162 
164 
165 extern void add_exact_object_address(const ObjectAddress *object,
166  ObjectAddresses *addrs);
167 
168 extern bool object_address_present(const ObjectAddress *object,
169  const ObjectAddresses *addrs);
170 
171 extern void record_object_address_dependencies(const ObjectAddress *depender,
172  ObjectAddresses *referenced,
173  DependencyType behavior);
174 
175 extern void sort_object_addresses(ObjectAddresses *addrs);
176 
177 extern void free_object_addresses(ObjectAddresses *addrs);
178 
179 /* in pg_depend.c */
180 
181 extern void recordDependencyOn(const ObjectAddress *depender,
182  const ObjectAddress *referenced,
183  DependencyType behavior);
184 
185 extern void recordMultipleDependencies(const ObjectAddress *depender,
186  const ObjectAddress *referenced,
187  int nreferenced,
188  DependencyType behavior);
189 
190 extern void recordDependencyOnCurrentExtension(const ObjectAddress *object,
191  bool isReplace);
192 
193 extern long deleteDependencyRecordsFor(Oid classId, Oid objectId,
194  bool skipExtensionDeps);
195 
196 extern long deleteDependencyRecordsForClass(Oid classId, Oid objectId,
197  Oid refclassId, char deptype);
198 
199 extern long changeDependencyFor(Oid classId, Oid objectId,
200  Oid refClassId, Oid oldRefObjectId,
201  Oid newRefObjectId);
202 
203 extern long changeDependenciesOf(Oid classId, Oid oldObjectId,
204  Oid newObjectId);
205 
206 extern long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId,
207  Oid newRefObjectId);
208 
209 extern Oid getExtensionOfObject(Oid classId, Oid objectId);
210 
211 extern bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId);
212 extern List *getOwnedSequences(Oid relid);
213 extern Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok);
214 
215 extern Oid get_constraint_index(Oid constraintId);
216 
217 extern Oid get_index_constraint(Oid indexId);
218 
219 extern List *get_index_ref_constraints(Oid indexId);
220 
221 /* in pg_shdepend.c */
222 
223 extern void recordSharedDependencyOn(ObjectAddress *depender,
224  ObjectAddress *referenced,
225  SharedDependencyType deptype);
226 
227 extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId,
228  int32 objectSubId);
229 
230 extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
231 
232 extern void changeDependencyOnOwner(Oid classId, Oid objectId,
233  Oid newOwnerId);
234 
235 extern void updateAclDependencies(Oid classId, Oid objectId, int32 objectSubId,
236  Oid ownerId,
237  int noldmembers, Oid *oldmembers,
238  int nnewmembers, Oid *newmembers);
239 
240 extern bool checkSharedDependencies(Oid classId, Oid objectId,
241  char **detail_msg, char **detail_log_msg);
242 
243 extern void shdepLockAndCheckObject(Oid classId, Oid objectId);
244 
245 extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
246 
247 extern void dropDatabaseDependencies(Oid databaseId);
248 
249 extern void shdepDropOwned(List *relids, DropBehavior behavior);
250 
251 extern void shdepReassignOwned(List *relids, Oid newrole);
252 
253 #endif /* DEPENDENCY_H */
List * getOwnedSequences(Oid relid)
Definition: pg_depend.c:771
DependencyType
Definition: dependency.h:31
void updateAclDependencies(Oid classId, Oid objectId, int32 objectSubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
Definition: pg_shdepend.c:427
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
Definition: pg_depend.c:663
void shdepLockAndCheckObject(Oid classId, Oid objectId)
Definition: pg_shdepend.c:1072
long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:463
void shdepReassignOwned(List *relids, Oid newrole)
Definition: pg_shdepend.c:1378
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
Definition: pg_shdepend.c:578
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
Definition: dependency.c:315
Definition: nodes.h:525
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
Definition: pg_depend.c:240
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:55
unsigned int Oid
Definition: postgres_ext.h:31
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:310
void dropDatabaseDependencies(Oid databaseId)
Definition: pg_shdepend.c:860
signed int int32
Definition: c.h:346
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: pg_depend.c:780
void sort_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2668
void copyTemplateDependencies(Oid templateDbId, Oid newDbId)
Definition: pg_shdepend.c:796
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:297
ObjectClass
Definition: dependency.h:89
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:908
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2695
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2680
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:165
SharedDependencyType
Definition: dependency.h:73
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
Definition: dependency.c:2500
DropBehavior
Definition: parsenodes.h:1740
Oid get_index_constraint(Oid indexId)
Definition: pg_depend.c:873
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Definition: pg_depend.c:190
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2440
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2385
List * get_index_ref_constraints(Oid indexId)
Definition: pg_depend.c:929
int16 attnum
Definition: pg_attribute.h:79
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
Definition: dependency.c:374
long changeDependenciesOf(Oid classId, Oid oldObjectId, Oid newObjectId)
Definition: pg_depend.c:407
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:610
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:138
Oid get_constraint_index(Oid constraintId)
Definition: pg_depend.c:806
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1586
void recordSharedDependencyOn(ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
Definition: pg_shdepend.c:121
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:43
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2649
void shdepDropOwned(List *relids, DropBehavior behavior)
Definition: pg_shdepend.c:1248
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
Definition: dependency.c:1629