]> granicus.if.org Git - postgresql/blob - src/include/catalog/dependency.h
Update CVS HEAD for 2007 copyright. Back branches are typically not
[postgresql] / src / include / catalog / dependency.h
1 /*-------------------------------------------------------------------------
2  *
3  * dependency.h
4  *        Routines to support inter-object dependencies.
5  *
6  *
7  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/catalog/dependency.h,v 1.29 2007/01/05 22:19:52 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef DEPENDENCY_H
15 #define DEPENDENCY_H
16
17 #include "nodes/parsenodes.h"   /* for DropBehavior */
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_PIN ('p'): there is no dependent object; this type of entry
53  * is a signal that the system itself depends on the referenced object,
54  * and so that object must never be deleted.  Entries of this type are
55  * created only during initdb.  The fields for the dependent object
56  * contain zeroes.
57  *
58  * Other dependency flavors may be needed in future.
59  *----------
60  */
61
62 typedef enum DependencyType
63 {
64         DEPENDENCY_NORMAL = 'n',
65         DEPENDENCY_AUTO = 'a',
66         DEPENDENCY_INTERNAL = 'i',
67         DEPENDENCY_PIN = 'p'
68 } DependencyType;
69
70 /*
71  * There is also a SharedDependencyType enum type that determines the exact
72  * semantics of an entry in pg_shdepend.  Just like regular dependency entries,
73  * any pg_shdepend entry means that the referenced object cannot be dropped
74  * unless the dependent object is dropped at the same time.  There are some
75  * additional rules however:
76  *
77  * (a) For a SHARED_DEPENDENCY_PIN entry, there is no dependent object --
78  * rather, the referenced object is an essential part of the system.  This
79  * applies to the initdb-created superuser.  Entries of this type are only
80  * created by initdb; objects in this category don't need further pg_shdepend
81  * entries if more objects come to depend on them.
82  *
83  * (b) a SHARED_DEPENDENCY_OWNER entry means that the referenced object is
84  * the role owning the dependent object.  The referenced object must be
85  * a pg_authid entry.
86  *
87  * (c) a SHARED_DEPENDENCY_ACL entry means that the referenced object is
88  * a role mentioned in the ACL field of the dependent object.  The referenced
89  * object must be a pg_authid entry.  (SHARED_DEPENDENCY_ACL entries are not
90  * created for the owner of an object; hence two objects may be linked by
91  * one or the other, but not both, of these dependency types.)
92  *
93  * SHARED_DEPENDENCY_INVALID is a value used as a parameter in internal
94  * routines, and is not valid in the catalog itself.
95  */
96 typedef enum SharedDependencyType
97 {
98         SHARED_DEPENDENCY_PIN = 'p',
99         SHARED_DEPENDENCY_OWNER = 'o',
100         SHARED_DEPENDENCY_ACL = 'a',
101         SHARED_DEPENDENCY_INVALID = 0
102 } SharedDependencyType;
103
104
105 /*
106  * The two objects related by a dependency are identified by ObjectAddresses.
107  */
108 typedef struct ObjectAddress
109 {
110         Oid                     classId;                /* Class Id from pg_class */
111         Oid                     objectId;               /* OID of the object */
112         int32           objectSubId;    /* Subitem within the object (column of table) */
113 } ObjectAddress;
114
115 /* expansible list of ObjectAddresses (private in dependency.c) */
116 typedef struct ObjectAddresses ObjectAddresses;
117
118 /*
119  * This enum covers all system catalogs whose OIDs can appear in
120  * pg_depend.classId or pg_shdepend.classId.
121  */
122 typedef enum ObjectClass
123 {
124         OCLASS_CLASS,                           /* pg_class */
125         OCLASS_PROC,                            /* pg_proc */
126         OCLASS_TYPE,                            /* pg_type */
127         OCLASS_CAST,                            /* pg_cast */
128         OCLASS_CONSTRAINT,                      /* pg_constraint */
129         OCLASS_CONVERSION,                      /* pg_conversion */
130         OCLASS_DEFAULT,                         /* pg_attrdef */
131         OCLASS_LANGUAGE,                        /* pg_language */
132         OCLASS_OPERATOR,                        /* pg_operator */
133         OCLASS_OPCLASS,                         /* pg_opclass */
134         OCLASS_OPFAMILY,                        /* pg_opfamily */
135         OCLASS_AMOP,                            /* pg_amop */
136         OCLASS_AMPROC,                          /* pg_amproc */
137         OCLASS_REWRITE,                         /* pg_rewrite */
138         OCLASS_TRIGGER,                         /* pg_trigger */
139         OCLASS_SCHEMA,                          /* pg_namespace */
140         OCLASS_ROLE,                            /* pg_authid */
141         OCLASS_DATABASE,                        /* pg_database */
142         OCLASS_TBLSPACE,                        /* pg_tablespace */
143         MAX_OCLASS                                      /* MUST BE LAST */
144 } ObjectClass;
145
146
147 /* in dependency.c */
148
149 extern void performDeletion(const ObjectAddress *object,
150                                 DropBehavior behavior);
151
152 extern void performMultipleDeletions(const ObjectAddresses *objects,
153                                                  DropBehavior behavior);
154
155 extern void deleteWhatDependsOn(const ObjectAddress *object,
156                                         bool showNotices);
157
158 extern void recordDependencyOnExpr(const ObjectAddress *depender,
159                                            Node *expr, List *rtable,
160                                            DependencyType behavior);
161
162 extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
163                                                                 Node *expr, Oid relId,
164                                                                 DependencyType behavior,
165                                                                 DependencyType self_behavior);
166
167 extern ObjectClass getObjectClass(const ObjectAddress *object);
168
169 extern char *getObjectDescription(const ObjectAddress *object);
170
171 extern ObjectAddresses *new_object_addresses(void);
172
173 extern void add_exact_object_address(const ObjectAddress *object,
174                                                  ObjectAddresses *addrs);
175
176 extern bool object_address_present(const ObjectAddress *object,
177                                            ObjectAddresses *addrs);
178
179 extern void free_object_addresses(ObjectAddresses *addrs);
180
181 /* in pg_depend.c */
182
183 extern void recordDependencyOn(const ObjectAddress *depender,
184                                    const ObjectAddress *referenced,
185                                    DependencyType behavior);
186
187 extern void recordMultipleDependencies(const ObjectAddress *depender,
188                                                    const ObjectAddress *referenced,
189                                                    int nreferenced,
190                                                    DependencyType behavior);
191
192 extern long deleteDependencyRecordsFor(Oid classId, Oid objectId);
193
194 extern long changeDependencyFor(Oid classId, Oid objectId,
195                                         Oid refClassId, Oid oldRefObjectId,
196                                         Oid newRefObjectId);
197
198 extern bool sequenceIsOwned(Oid seqId, Oid *tableId, int32 *colId);
199
200 extern void markSequenceUnowned(Oid seqId);
201
202 /* in pg_shdepend.c */
203
204 extern void recordSharedDependencyOn(ObjectAddress *depender,
205                                                  ObjectAddress *referenced,
206                                                  SharedDependencyType deptype);
207
208 extern void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId);
209
210 extern void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner);
211
212 extern void changeDependencyOnOwner(Oid classId, Oid objectId,
213                                                 Oid newOwnerId);
214
215 extern void updateAclDependencies(Oid classId, Oid objectId,
216                                           Oid ownerId, bool isGrant,
217                                           int noldmembers, Oid *oldmembers,
218                                           int nnewmembers, Oid *newmembers);
219
220 extern char *checkSharedDependencies(Oid classId, Oid objectId);
221
222 extern void copyTemplateDependencies(Oid templateDbId, Oid newDbId);
223
224 extern void dropDatabaseDependencies(Oid databaseId);
225
226 extern void shdepDropOwned(List *relids, DropBehavior behavior);
227
228 extern void shdepReassignOwned(List *relids, Oid newrole);
229
230 #endif   /* DEPENDENCY_H */