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-2022, 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 {
41 
42 /*
43  * There is also a SharedDependencyType enum type that determines the exact
44  * semantics of an entry in pg_shdepend. Just like regular dependency entries,
45  * any pg_shdepend entry means that the referenced object cannot be dropped
46  * unless the dependent object is dropped at the same time. There are some
47  * additional rules however:
48  *
49  * (a) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is
50  * the role owning the dependent object. The referenced object must be
51  * a pg_authid entry.
52  *
53  * (b) a SHARED_DEPENDENCY_ACL entry means that the referenced object is
54  * a role mentioned in the ACL field of the dependent object. The referenced
55  * object must be a pg_authid entry. (SHARED_DEPENDENCY_ACL entries are not
56  * created for the owner of an object; hence two objects may be linked by
57  * one or the other, but not both, of these dependency types.)
58  *
59  * (c) a SHARED_DEPENDENCY_POLICY entry means that the referenced object is
60  * a role mentioned in a policy object. The referenced object must be a
61  * pg_authid entry.
62  *
63  * (d) a SHARED_DEPENDENCY_TABLESPACE entry means that the referenced
64  * object is a tablespace mentioned in a relation without storage. The
65  * referenced object must be a pg_tablespace entry. (Relations that have
66  * storage don't need this: they are protected by the existence of a physical
67  * file in the tablespace.)
68  *
69  * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
70  * routines, and is not valid in the catalog itself.
71  */
73 {
80 
81 /* expansible list of ObjectAddresses (private in dependency.c) */
82 typedef struct ObjectAddresses ObjectAddresses;
83 
84 /*
85  * This enum covers all system catalogs whose OIDs can appear in
86  * pg_depend.classId or pg_shdepend.classId. Keep object_classes[] in sync.
87  */
88 typedef enum ObjectClass
89 {
90  OCLASS_CLASS, /* pg_class */
91  OCLASS_PROC, /* pg_proc */
92  OCLASS_TYPE, /* pg_type */
93  OCLASS_CAST, /* pg_cast */
94  OCLASS_COLLATION, /* pg_collation */
95  OCLASS_CONSTRAINT, /* pg_constraint */
96  OCLASS_CONVERSION, /* pg_conversion */
97  OCLASS_DEFAULT, /* pg_attrdef */
98  OCLASS_LANGUAGE, /* pg_language */
99  OCLASS_LARGEOBJECT, /* pg_largeobject */
100  OCLASS_OPERATOR, /* pg_operator */
101  OCLASS_OPCLASS, /* pg_opclass */
102  OCLASS_OPFAMILY, /* pg_opfamily */
103  OCLASS_AM, /* pg_am */
104  OCLASS_AMOP, /* pg_amop */
105  OCLASS_AMPROC, /* pg_amproc */
106  OCLASS_REWRITE, /* pg_rewrite */
107  OCLASS_TRIGGER, /* pg_trigger */
108  OCLASS_SCHEMA, /* pg_namespace */
109  OCLASS_STATISTIC_EXT, /* pg_statistic_ext */
110  OCLASS_TSPARSER, /* pg_ts_parser */
111  OCLASS_TSDICT, /* pg_ts_dict */
112  OCLASS_TSTEMPLATE, /* pg_ts_template */
113  OCLASS_TSCONFIG, /* pg_ts_config */
114  OCLASS_ROLE, /* pg_authid */
115  OCLASS_ROLE_MEMBERSHIP, /* pg_auth_members */
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_PARAMETER_ACL, /* pg_parameter_acl */
125  OCLASS_POLICY, /* pg_policy */
126  OCLASS_PUBLICATION, /* pg_publication */
127  OCLASS_PUBLICATION_NAMESPACE, /* pg_publication_namespace */
128  OCLASS_PUBLICATION_REL, /* pg_publication_rel */
129  OCLASS_SUBSCRIPTION, /* pg_subscription */
130  OCLASS_TRANSFORM /* pg_transform */
132 
133 #define LAST_OCLASS OCLASS_TRANSFORM
134 
135 /* flag bits for performDeletion/performMultipleDeletions: */
136 #define PERFORM_DELETION_INTERNAL 0x0001 /* internal action */
137 #define PERFORM_DELETION_CONCURRENTLY 0x0002 /* concurrent drop */
138 #define PERFORM_DELETION_QUIETLY 0x0004 /* suppress notices */
139 #define PERFORM_DELETION_SKIP_ORIGINAL 0x0008 /* keep original obj */
140 #define PERFORM_DELETION_SKIP_EXTENSIONS 0x0010 /* keep extensions */
141 #define PERFORM_DELETION_CONCURRENT_LOCK 0x0020 /* normal drop with
142  * concurrent lock mode */
143 
144 
145 /* in dependency.c */
146 
147 extern void AcquireDeletionLock(const ObjectAddress *object, int flags);
148 
149 extern void ReleaseDeletionLock(const ObjectAddress *object);
150 
151 extern void performDeletion(const ObjectAddress *object,
152  DropBehavior behavior, int flags);
153 
154 extern void performMultipleDeletions(const ObjectAddresses *objects,
155  DropBehavior behavior, int flags);
156 
157 extern void recordDependencyOnExpr(const ObjectAddress *depender,
158  Node *expr, List *rtable,
159  DependencyType behavior);
160 
161 extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
162  Node *expr, Oid relId,
163  DependencyType behavior,
164  DependencyType self_behavior,
165  bool reverse_self);
166 
167 extern ObjectClass getObjectClass(const ObjectAddress *object);
168 
170 
171 extern void add_exact_object_address(const ObjectAddress *object,
172  ObjectAddresses *addrs);
173 
174 extern bool object_address_present(const ObjectAddress *object,
175  const ObjectAddresses *addrs);
176 
177 extern void record_object_address_dependencies(const ObjectAddress *depender,
178  ObjectAddresses *referenced,
179  DependencyType behavior);
180 
181 extern void sort_object_addresses(ObjectAddresses *addrs);
182 
183 extern void free_object_addresses(ObjectAddresses *addrs);
184 
185 /* in pg_depend.c */
186 
187 extern void recordDependencyOn(const ObjectAddress *depender,
188  const ObjectAddress *referenced,
189  DependencyType behavior);
190 
191 extern void recordMultipleDependencies(const ObjectAddress *depender,
192  const ObjectAddress *referenced,
193  int nreferenced,
194  DependencyType behavior);
195 
196 extern void recordDependencyOnCurrentExtension(const ObjectAddress *object,
197  bool isReplace);
198 
199 extern void checkMembershipInCurrentExtension(const ObjectAddress *object);
200 
201 extern long deleteDependencyRecordsFor(Oid classId, Oid objectId,
202  bool skipExtensionDeps);
203 
204 extern long deleteDependencyRecordsForClass(Oid classId, Oid objectId,
205  Oid refclassId, char deptype);
206 
207 extern long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId,
208  char deptype,
209  Oid refclassId, Oid refobjectId);
210 
211 extern long changeDependencyFor(Oid classId, Oid objectId,
212  Oid refClassId, Oid oldRefObjectId,
213  Oid newRefObjectId);
214 
215 extern long changeDependenciesOf(Oid classId, Oid oldObjectId,
216  Oid newObjectId);
217 
218 extern long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId,
219  Oid newRefObjectId);
220 
221 extern Oid getExtensionOfObject(Oid classId, Oid objectId);
222 extern List *getAutoExtensionsOfObject(Oid classId, Oid objectId);
223 
224 extern bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId);
225 extern List *getOwnedSequences(Oid relid);
226 extern Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok);
227 
228 extern Oid get_index_constraint(Oid indexId);
229 
230 extern List *get_index_ref_constraints(Oid indexId);
231 
232 /* in pg_shdepend.c */
233 
234 extern void recordSharedDependencyOn(ObjectAddress *depender,
235  ObjectAddress *referenced,
236  SharedDependencyType deptype);
237 
238 extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId,
239  int32 objectSubId);
240 
241 extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
242 
243 extern void changeDependencyOnOwner(Oid classId, Oid objectId,
244  Oid newOwnerId);
245 
246 extern void recordDependencyOnTablespace(Oid classId, Oid objectId,
247  Oid tablespace);
248 
249 extern void changeDependencyOnTablespace(Oid classId, Oid objectId,
250  Oid newTablespaceId);
251 
252 extern void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId,
253  Oid ownerId,
254  int noldmembers, Oid *oldmembers,
255  int nnewmembers, Oid *newmembers);
256 
257 extern bool checkSharedDependencies(Oid classId, Oid objectId,
258  char **detail_msg, char **detail_log_msg);
259 
260 extern void shdepLockAndCheckObject(Oid classId, Oid objectId);
261 
262 extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
263 
264 extern void dropDatabaseDependencies(Oid databaseId);
265 
266 extern void shdepDropOwned(List *roleids, DropBehavior behavior);
267 
268 extern void shdepReassignOwned(List *roleids, Oid newrole);
269 
270 #endif /* DEPENDENCY_H */
int16 AttrNumber
Definition: attnum.h:21
signed int int32
Definition: c.h:430
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
Definition: dependency.c:381
void checkMembershipInCurrentExtension(const ObjectAddress *object)
Definition: pg_depend.c:257
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:56
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2790
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:456
DependencyType
Definition: dependency.h:32
@ DEPENDENCY_AUTO
Definition: dependency.h:34
@ DEPENDENCY_AUTO_EXTENSION
Definition: dependency.h:39
@ DEPENDENCY_INTERNAL
Definition: dependency.h:35
@ DEPENDENCY_PARTITION_PRI
Definition: dependency.h:36
@ DEPENDENCY_PARTITION_SEC
Definition: dependency.h:37
@ DEPENDENCY_EXTENSION
Definition: dependency.h:38
@ DEPENDENCY_NORMAL
Definition: dependency.h:33
void sort_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2809
SharedDependencyType
Definition: dependency.h:73
@ SHARED_DEPENDENCY_TABLESPACE
Definition: dependency.h:77
@ SHARED_DEPENDENCY_INVALID
Definition: dependency.h:78
@ SHARED_DEPENDENCY_POLICY
Definition: dependency.h:76
@ SHARED_DEPENDENCY_ACL
Definition: dependency.h:75
@ SHARED_DEPENDENCY_OWNER
Definition: dependency.h:74
List * getAutoExtensionsOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:777
void dropDatabaseDependencies(Oid databaseId)
Definition: pg_shdepend.c:954
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:313
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
Definition: pg_depend.c:350
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:731
void AcquireDeletionLock(const ObjectAddress *object, int flags)
Definition: dependency.c:1539
void copyTemplateDependencies(Oid templateDbId, Oid newDbId)
Definition: pg_shdepend.c:850
long changeDependenciesOf(Oid classId, Oid oldObjectId, Oid newObjectId)
Definition: pg_depend.c:564
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2836
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
Definition: dependency.c:322
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:1002
void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
Definition: pg_shdepend.c:482
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:165
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
Definition: pg_depend.c:300
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
Definition: pg_shdepend.c:631
void recordDependencyOnTablespace(Oid classId, Oid objectId, Oid tablespace)
Definition: pg_shdepend.c:361
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Definition: pg_depend.c:397
long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:620
void ReleaseDeletionLock(const ObjectAddress *object)
Definition: dependency.c:1571
void shdepDropOwned(List *roleids, DropBehavior behavior)
Definition: pg_shdepend.c:1295
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
Definition: dependency.c:1639
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1596
void recordSharedDependencyOn(ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
Definition: pg_shdepend.c:122
void shdepLockAndCheckObject(Oid classId, Oid objectId)
Definition: pg_shdepend.c:1166
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
Definition: dependency.c:2641
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2526
Oid get_index_constraint(Oid indexId)
Definition: pg_depend.c:968
List * get_index_ref_constraints(Oid indexId)
Definition: pg_depend.c:1024
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2581
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: pg_depend.c:944
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:192
ObjectClass
Definition: dependency.h:89
@ OCLASS_OPERATOR
Definition: dependency.h:100
@ OCLASS_PARAMETER_ACL
Definition: dependency.h:124
@ OCLASS_LARGEOBJECT
Definition: dependency.h:99
@ OCLASS_FDW
Definition: dependency.h:118
@ OCLASS_OPFAMILY
Definition: dependency.h:102
@ OCLASS_DEFACL
Definition: dependency.h:121
@ OCLASS_TSPARSER
Definition: dependency.h:110
@ OCLASS_TRIGGER
Definition: dependency.h:107
@ OCLASS_DEFAULT
Definition: dependency.h:97
@ OCLASS_TSTEMPLATE
Definition: dependency.h:112
@ OCLASS_AMPROC
Definition: dependency.h:105
@ OCLASS_TBLSPACE
Definition: dependency.h:117
@ OCLASS_TSCONFIG
Definition: dependency.h:113
@ OCLASS_TYPE
Definition: dependency.h:92
@ OCLASS_LANGUAGE
Definition: dependency.h:98
@ OCLASS_CAST
Definition: dependency.h:93
@ OCLASS_SUBSCRIPTION
Definition: dependency.h:129
@ OCLASS_PUBLICATION_NAMESPACE
Definition: dependency.h:127
@ OCLASS_EXTENSION
Definition: dependency.h:122
@ OCLASS_COLLATION
Definition: dependency.h:94
@ OCLASS_FOREIGN_SERVER
Definition: dependency.h:119
@ OCLASS_REWRITE
Definition: dependency.h:106
@ OCLASS_STATISTIC_EXT
Definition: dependency.h:109
@ OCLASS_PROC
Definition: dependency.h:91
@ OCLASS_OPCLASS
Definition: dependency.h:101
@ OCLASS_CONVERSION
Definition: dependency.h:96
@ OCLASS_DATABASE
Definition: dependency.h:116
@ OCLASS_ROLE_MEMBERSHIP
Definition: dependency.h:115
@ OCLASS_SCHEMA
Definition: dependency.h:108
@ OCLASS_EVENT_TRIGGER
Definition: dependency.h:123
@ OCLASS_CLASS
Definition: dependency.h:90
@ OCLASS_TRANSFORM
Definition: dependency.h:130
@ OCLASS_ROLE
Definition: dependency.h:114
@ OCLASS_CONSTRAINT
Definition: dependency.h:95
@ OCLASS_POLICY
Definition: dependency.h:125
@ OCLASS_USER_MAPPING
Definition: dependency.h:120
@ OCLASS_PUBLICATION_REL
Definition: dependency.h:128
@ OCLASS_AM
Definition: dependency.h:103
@ OCLASS_TSDICT
Definition: dependency.h:111
@ OCLASS_PUBLICATION
Definition: dependency.h:126
@ OCLASS_AMOP
Definition: dependency.h:104
List * getOwnedSequences(Oid relid)
Definition: pg_depend.c:935
void changeDependencyOnTablespace(Oid classId, Oid objectId, Oid newTablespaceId)
Definition: pg_shdepend.c:382
void shdepReassignOwned(List *roleids, Oid newrole)
Definition: pg_shdepend.c:1467
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
Definition: pg_depend.c:827
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2821
DropBehavior
Definition: parsenodes.h:1932
int16 attnum
Definition: pg_attribute.h:83
char * tablespace
Definition: pgbench.c:225
unsigned int Oid
Definition: postgres_ext.h:31
Definition: pg_list.h:52
Definition: nodes.h:112