OSDN Git Service

rebuid:
[eos/hostdependX86MAC64.git] / util / X86MAC64 / include / postgresql / server / catalog / pg_constraint.h
1 /*-------------------------------------------------------------------------
2  *
3  * pg_constraint.h
4  *        definition of the system "constraint" relation (pg_constraint)
5  *        along with the relation's initial contents.
6  *
7  *
8  * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * src/include/catalog/pg_constraint.h
12  *
13  * NOTES
14  *        the genbki.pl script reads this file and generates .bki
15  *        information from the DATA() statements.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PG_CONSTRAINT_H
20 #define PG_CONSTRAINT_H
21
22 #include "catalog/genbki.h"
23 #include "catalog/dependency.h"
24 #include "nodes/pg_list.h"
25
26 /* ----------------
27  *              pg_constraint definition.  cpp turns this into
28  *              typedef struct FormData_pg_constraint
29  * ----------------
30  */
31 #define ConstraintRelationId  2606
32
33 CATALOG(pg_constraint,2606)
34 {
35         /*
36          * conname + connamespace is deliberately not unique; we allow, for
37          * example, the same name to be used for constraints of different
38          * relations.  This is partly for backwards compatibility with past
39          * Postgres practice, and partly because we don't want to have to obtain a
40          * global lock to generate a globally unique name for a nameless
41          * constraint.  We associate a namespace with constraint names only for
42          * SQL-spec compatibility.
43          */
44         NameData        conname;                /* name of this constraint */
45         Oid                     connamespace;   /* OID of namespace containing constraint */
46         char            contype;                /* constraint type; see codes below */
47         bool            condeferrable;  /* deferrable constraint? */
48         bool            condeferred;    /* deferred by default? */
49         bool            convalidated;   /* constraint has been validated? */
50
51         /*
52          * conrelid and conkey are only meaningful if the constraint applies to a
53          * specific relation (this excludes domain constraints and assertions).
54          * Otherwise conrelid is 0 and conkey is NULL.
55          */
56         Oid                     conrelid;               /* relation this constraint constrains */
57
58         /*
59          * contypid links to the pg_type row for a domain if this is a domain
60          * constraint.  Otherwise it's 0.
61          *
62          * For SQL-style global ASSERTIONs, both conrelid and contypid would be
63          * zero. This is not presently supported, however.
64          */
65         Oid                     contypid;               /* domain this constraint constrains */
66
67         /*
68          * conindid links to the index supporting the constraint, if any;
69          * otherwise it's 0.  This is used for unique, primary-key, and exclusion
70          * constraints, and less obviously for foreign-key constraints (where the
71          * index is a unique index on the referenced relation's referenced
72          * columns).  Notice that the index is on conrelid in the first case but
73          * confrelid in the second.
74          */
75         Oid                     conindid;               /* index supporting this constraint */
76
77         /*
78          * These fields, plus confkey, are only meaningful for a foreign-key
79          * constraint.  Otherwise confrelid is 0 and the char fields are spaces.
80          */
81         Oid                     confrelid;              /* relation referenced by foreign key */
82         char            confupdtype;    /* foreign key's ON UPDATE action */
83         char            confdeltype;    /* foreign key's ON DELETE action */
84         char            confmatchtype;  /* foreign key's match type */
85
86         /* Has a local definition (hence, do not drop when coninhcount is 0) */
87         bool            conislocal;
88
89         /* Number of times inherited from direct parent relation(s) */
90         int32           coninhcount;
91
92         /* Has a local definition and cannot be inherited */
93         bool            connoinherit;
94
95 #ifdef CATALOG_VARLEN                   /* variable-length fields start here */
96
97         /*
98          * Columns of conrelid that the constraint applies to, if known (this is
99          * NULL for trigger constraints)
100          */
101         int16           conkey[1];
102
103         /*
104          * If a foreign key, the referenced columns of confrelid
105          */
106         int16           confkey[1];
107
108         /*
109          * If a foreign key, the OIDs of the PK = FK equality operators for each
110          * column of the constraint
111          */
112         Oid                     conpfeqop[1];
113
114         /*
115          * If a foreign key, the OIDs of the PK = PK equality operators for each
116          * column of the constraint (i.e., equality for the referenced columns)
117          */
118         Oid                     conppeqop[1];
119
120         /*
121          * If a foreign key, the OIDs of the FK = FK equality operators for each
122          * column of the constraint (i.e., equality for the referencing columns)
123          */
124         Oid                     conffeqop[1];
125
126         /*
127          * If an exclusion constraint, the OIDs of the exclusion operators for
128          * each column of the constraint
129          */
130         Oid                     conexclop[1];
131
132         /*
133          * If a check constraint, nodeToString representation of expression
134          */
135         pg_node_tree conbin;
136
137         /*
138          * If a check constraint, source-text representation of expression
139          */
140         text            consrc;
141 #endif
142 } FormData_pg_constraint;
143
144 /* ----------------
145  *              Form_pg_constraint corresponds to a pointer to a tuple with
146  *              the format of pg_constraint relation.
147  * ----------------
148  */
149 typedef FormData_pg_constraint *Form_pg_constraint;
150
151 /* ----------------
152  *              compiler constants for pg_constraint
153  * ----------------
154  */
155 #define Natts_pg_constraint                                     24
156 #define Anum_pg_constraint_conname                      1
157 #define Anum_pg_constraint_connamespace         2
158 #define Anum_pg_constraint_contype                      3
159 #define Anum_pg_constraint_condeferrable        4
160 #define Anum_pg_constraint_condeferred          5
161 #define Anum_pg_constraint_convalidated         6
162 #define Anum_pg_constraint_conrelid                     7
163 #define Anum_pg_constraint_contypid                     8
164 #define Anum_pg_constraint_conindid                     9
165 #define Anum_pg_constraint_confrelid            10
166 #define Anum_pg_constraint_confupdtype          11
167 #define Anum_pg_constraint_confdeltype          12
168 #define Anum_pg_constraint_confmatchtype        13
169 #define Anum_pg_constraint_conislocal           14
170 #define Anum_pg_constraint_coninhcount          15
171 #define Anum_pg_constraint_connoinherit         16
172 #define Anum_pg_constraint_conkey                       17
173 #define Anum_pg_constraint_confkey                      18
174 #define Anum_pg_constraint_conpfeqop            19
175 #define Anum_pg_constraint_conppeqop            20
176 #define Anum_pg_constraint_conffeqop            21
177 #define Anum_pg_constraint_conexclop            22
178 #define Anum_pg_constraint_conbin                       23
179 #define Anum_pg_constraint_consrc                       24
180
181
182 /* Valid values for contype */
183 #define CONSTRAINT_CHECK                        'c'
184 #define CONSTRAINT_FOREIGN                      'f'
185 #define CONSTRAINT_PRIMARY                      'p'
186 #define CONSTRAINT_UNIQUE                       'u'
187 #define CONSTRAINT_TRIGGER                      't'
188 #define CONSTRAINT_EXCLUSION            'x'
189
190 /*
191  * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
192  * constants defined in parsenodes.h.  Valid values for confmatchtype are
193  * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
194  */
195
196 /*
197  * Identify constraint type for lookup purposes
198  */
199 typedef enum ConstraintCategory
200 {
201         CONSTRAINT_RELATION,
202         CONSTRAINT_DOMAIN,
203         CONSTRAINT_ASSERTION            /* for future expansion */
204 } ConstraintCategory;
205
206 /*
207  * prototypes for functions in pg_constraint.c
208  */
209 extern Oid CreateConstraintEntry(const char *constraintName,
210                                           Oid constraintNamespace,
211                                           char constraintType,
212                                           bool isDeferrable,
213                                           bool isDeferred,
214                                           bool isValidated,
215                                           Oid relId,
216                                           const int16 *constraintKey,
217                                           int constraintNKeys,
218                                           Oid domainId,
219                                           Oid indexRelId,
220                                           Oid foreignRelId,
221                                           const int16 *foreignKey,
222                                           const Oid *pfEqOp,
223                                           const Oid *ppEqOp,
224                                           const Oid *ffEqOp,
225                                           int foreignNKeys,
226                                           char foreignUpdateType,
227                                           char foreignDeleteType,
228                                           char foreignMatchType,
229                                           const Oid *exclOp,
230                                           Node *conExpr,
231                                           const char *conBin,
232                                           const char *conSrc,
233                                           bool conIsLocal,
234                                           int conInhCount,
235                                           bool conNoInherit,
236                                           bool is_internal);
237
238 extern void RemoveConstraintById(Oid conId);
239 extern void RenameConstraintById(Oid conId, const char *newname);
240 extern void SetValidatedConstraintById(Oid conId);
241
242 extern bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId,
243                                          Oid objNamespace, const char *conname);
244 extern char *ChooseConstraintName(const char *name1, const char *name2,
245                                          const char *label, Oid namespaceid,
246                                          List *others);
247
248 extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
249                                           Oid newNspId, bool isType, ObjectAddresses *objsMoved);
250 extern void get_constraint_relation_oids(Oid constraint_oid, Oid *conrelid, Oid *confrelid);
251 extern Oid      get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok);
252 extern Oid      get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok);
253
254 extern bool check_functional_grouping(Oid relid,
255                                                   Index varno, Index varlevelsup,
256                                                   List *grouping_columns,
257                                                   List **constraintDeps);
258
259 #endif   /* PG_CONSTRAINT_H */