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-2024, 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_INITACL entry means that the referenced object is
60  * a role mentioned in a pg_init_privs entry for the dependent object. The
61  * referenced object must be a pg_authid entry. (SHARED_DEPENDENCY_INITACL
62  * entries are not created for the owner of an object; hence two objects may
63  * be linked by one or the other, but not both, of these dependency types.)
64  *
65  * (d) a SHARED_DEPENDENCY_POLICY entry means that the referenced object is
66  * a role mentioned in a policy object. The referenced object must be a
67  * pg_authid entry.
68  *
69  * (e) a SHARED_DEPENDENCY_TABLESPACE entry means that the referenced
70  * object is a tablespace mentioned in a relation without storage. The
71  * referenced object must be a pg_tablespace entry. (Relations that have
72  * storage don't need this: they are protected by the existence of a physical
73  * file in the tablespace.)
74  *
75  * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
76  * routines, and is not valid in the catalog itself.
77  */
79 {
87 
88 /* expansible list of ObjectAddresses (private in dependency.c) */
89 typedef struct ObjectAddresses ObjectAddresses;
90 
91 /* flag bits for performDeletion/performMultipleDeletions: */
92 #define PERFORM_DELETION_INTERNAL 0x0001 /* internal action */
93 #define PERFORM_DELETION_CONCURRENTLY 0x0002 /* concurrent drop */
94 #define PERFORM_DELETION_QUIETLY 0x0004 /* suppress notices */
95 #define PERFORM_DELETION_SKIP_ORIGINAL 0x0008 /* keep original obj */
96 #define PERFORM_DELETION_SKIP_EXTENSIONS 0x0010 /* keep extensions */
97 #define PERFORM_DELETION_CONCURRENT_LOCK 0x0020 /* normal drop with
98  * concurrent lock mode */
99 
100 
101 /* in dependency.c */
102 
103 extern void AcquireDeletionLock(const ObjectAddress *object, int flags);
104 
105 extern void ReleaseDeletionLock(const ObjectAddress *object);
106 
107 extern void performDeletion(const ObjectAddress *object,
108  DropBehavior behavior, int flags);
109 
110 extern void performMultipleDeletions(const ObjectAddresses *objects,
111  DropBehavior behavior, int flags);
112 
113 extern void recordDependencyOnExpr(const ObjectAddress *depender,
114  Node *expr, List *rtable,
115  DependencyType behavior);
116 
117 extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
118  Node *expr, Oid relId,
119  DependencyType behavior,
120  DependencyType self_behavior,
121  bool reverse_self);
122 
124 
125 extern void add_exact_object_address(const ObjectAddress *object,
126  ObjectAddresses *addrs);
127 
128 extern bool object_address_present(const ObjectAddress *object,
129  const ObjectAddresses *addrs);
130 
131 extern void record_object_address_dependencies(const ObjectAddress *depender,
132  ObjectAddresses *referenced,
133  DependencyType behavior);
134 
135 extern void sort_object_addresses(ObjectAddresses *addrs);
136 
137 extern void free_object_addresses(ObjectAddresses *addrs);
138 
139 /* in pg_depend.c */
140 
141 extern void recordDependencyOn(const ObjectAddress *depender,
142  const ObjectAddress *referenced,
143  DependencyType behavior);
144 
145 extern void recordMultipleDependencies(const ObjectAddress *depender,
146  const ObjectAddress *referenced,
147  int nreferenced,
148  DependencyType behavior);
149 
150 extern void recordDependencyOnCurrentExtension(const ObjectAddress *object,
151  bool isReplace);
152 
153 extern void checkMembershipInCurrentExtension(const ObjectAddress *object);
154 
155 extern long deleteDependencyRecordsFor(Oid classId, Oid objectId,
156  bool skipExtensionDeps);
157 
158 extern long deleteDependencyRecordsForClass(Oid classId, Oid objectId,
159  Oid refclassId, char deptype);
160 
161 extern long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId,
162  char deptype,
163  Oid refclassId, Oid refobjectId);
164 
165 extern long changeDependencyFor(Oid classId, Oid objectId,
166  Oid refClassId, Oid oldRefObjectId,
167  Oid newRefObjectId);
168 
169 extern long changeDependenciesOf(Oid classId, Oid oldObjectId,
170  Oid newObjectId);
171 
172 extern long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId,
173  Oid newRefObjectId);
174 
175 extern Oid getExtensionOfObject(Oid classId, Oid objectId);
176 extern List *getAutoExtensionsOfObject(Oid classId, Oid objectId);
177 
178 extern bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId);
179 extern List *getOwnedSequences(Oid relid);
180 extern Oid getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok);
181 
182 extern Oid get_index_constraint(Oid indexId);
183 
184 extern List *get_index_ref_constraints(Oid indexId);
185 
186 /* in pg_shdepend.c */
187 
188 extern void recordSharedDependencyOn(ObjectAddress *depender,
189  ObjectAddress *referenced,
190  SharedDependencyType deptype);
191 
192 extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId,
193  int32 objectSubId);
194 
195 extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
196 
197 extern void changeDependencyOnOwner(Oid classId, Oid objectId,
198  Oid newOwnerId);
199 
200 extern void recordDependencyOnTablespace(Oid classId, Oid objectId,
201  Oid tablespace);
202 
203 extern void changeDependencyOnTablespace(Oid classId, Oid objectId,
204  Oid newTablespaceId);
205 
206 extern void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId,
207  Oid ownerId,
208  int noldmembers, Oid *oldmembers,
209  int nnewmembers, Oid *newmembers);
210 
211 extern void updateInitAclDependencies(Oid classId, Oid objectId, int32 objsubId,
212  Oid ownerId,
213  int noldmembers, Oid *oldmembers,
214  int nnewmembers, Oid *newmembers);
215 
216 extern bool checkSharedDependencies(Oid classId, Oid objectId,
217  char **detail_msg, char **detail_log_msg);
218 
219 extern void shdepLockAndCheckObject(Oid classId, Oid objectId);
220 
221 extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
222 
223 extern void dropDatabaseDependencies(Oid databaseId);
224 
225 extern void shdepDropOwned(List *roleids, DropBehavior behavior);
226 
227 extern void shdepReassignOwned(List *roleids, Oid newrole);
228 
229 #endif /* DEPENDENCY_H */
int16 AttrNumber
Definition: attnum.h:21
signed int int32
Definition: c.h:494
void performMultipleDeletions(const ObjectAddresses *objects, DropBehavior behavior, int flags)
Definition: dependency.c:332
void checkMembershipInCurrentExtension(const ObjectAddress *object)
Definition: pg_depend.c:259
void recordMultipleDependencies(const ObjectAddress *depender, const ObjectAddress *referenced, int nreferenced, DependencyType behavior)
Definition: pg_depend.c:58
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
Definition: dependency.c:2740
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:46
long changeDependencyFor(Oid classId, Oid objectId, Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:458
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:2759
SharedDependencyType
Definition: dependency.h:79
@ SHARED_DEPENDENCY_INITACL
Definition: dependency.h:82
@ SHARED_DEPENDENCY_TABLESPACE
Definition: dependency.h:84
@ SHARED_DEPENDENCY_INVALID
Definition: dependency.h:85
@ SHARED_DEPENDENCY_POLICY
Definition: dependency.h:83
@ SHARED_DEPENDENCY_ACL
Definition: dependency.h:81
@ SHARED_DEPENDENCY_OWNER
Definition: dependency.h:80
List * getAutoExtensionsOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:779
void dropDatabaseDependencies(Oid databaseId)
Definition: pg_shdepend.c:991
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:352
Oid getExtensionOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:733
void AcquireDeletionLock(const ObjectAddress *object, int flags)
Definition: dependency.c:1494
void copyTemplateDependencies(Oid templateDbId, Oid newDbId)
Definition: pg_shdepend.c:887
long changeDependenciesOf(Oid classId, Oid oldObjectId, Oid newObjectId)
Definition: pg_depend.c:566
void performDeletion(const ObjectAddress *object, DropBehavior behavior, int flags)
Definition: dependency.c:273
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Definition: pg_shdepend.c:1039
void updateAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
Definition: pg_shdepend.c:487
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:302
bool checkSharedDependencies(Oid classId, Oid objectId, char **detail_msg, char **detail_log_msg)
Definition: pg_shdepend.c:668
void recordDependencyOnTablespace(Oid classId, Oid objectId, Oid tablespace)
Definition: pg_shdepend.c:366
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Definition: pg_depend.c:399
long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)
Definition: pg_depend.c:622
void ReleaseDeletionLock(const ObjectAddress *object)
Definition: dependency.c:1526
void shdepDropOwned(List *roleids, DropBehavior behavior)
Definition: pg_shdepend.c:1334
void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)
Definition: dependency.c:1594
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
Definition: dependency.c:1551
void recordSharedDependencyOn(ObjectAddress *depender, ObjectAddress *referenced, SharedDependencyType deptype)
Definition: pg_shdepend.c:122
Oid getIdentitySequence(Relation rel, AttrNumber attnum, bool missing_ok)
Definition: pg_depend.c:946
void shdepLockAndCheckObject(Oid classId, Oid objectId)
Definition: pg_shdepend.c:1203
bool object_address_present(const ObjectAddress *object, const ObjectAddresses *addrs)
Definition: dependency.c:2591
ObjectAddresses * new_object_addresses(void)
Definition: dependency.c:2485
Oid get_index_constraint(Oid indexId)
Definition: pg_depend.c:995
List * get_index_ref_constraints(Oid indexId)
Definition: pg_depend.c:1051
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
Definition: dependency.c:2531
void updateInitAclDependencies(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, int noldmembers, Oid *oldmembers, int nnewmembers, Oid *newmembers)
Definition: pg_shdepend.c:506
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:194
List * getOwnedSequences(Oid relid)
Definition: pg_depend.c:937
void changeDependencyOnTablespace(Oid classId, Oid objectId, Oid newTablespaceId)
Definition: pg_shdepend.c:387
void shdepReassignOwned(List *roleids, Oid newrole)
Definition: pg_shdepend.c:1515
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
Definition: pg_depend.c:829
void free_object_addresses(ObjectAddresses *addrs)
Definition: dependency.c:2771
DropBehavior
Definition: parsenodes.h:2333
int16 attnum
Definition: pg_attribute.h:74
char * tablespace
Definition: pgbench.c:216
unsigned int Oid
Definition: postgres_ext.h:31
Definition: pg_list.h:54
Definition: nodes.h:129