2002-07-12 20:43:19 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* pg_constraint.h
|
|
|
|
* definition of the system "constraint" relation (pg_constraint)
|
|
|
|
* along with the relation's initial contents.
|
|
|
|
*
|
|
|
|
*
|
2014-01-07 22:05:30 +01:00
|
|
|
* Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
|
2002-07-12 20:43:19 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/catalog/pg_constraint.h
|
2002-07-12 20:43:19 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
2010-01-05 02:06:57 +01:00
|
|
|
* the genbki.pl script reads this file and generates .bki
|
2002-07-12 20:43:19 +02:00
|
|
|
* information from the DATA() statements.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PG_CONSTRAINT_H
|
|
|
|
#define PG_CONSTRAINT_H
|
|
|
|
|
2008-03-27 04:57:34 +01:00
|
|
|
#include "catalog/genbki.h"
|
2012-10-31 14:52:55 +01:00
|
|
|
#include "catalog/dependency.h"
|
2006-06-29 00:11:01 +02:00
|
|
|
#include "nodes/pg_list.h"
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/* ----------------
|
|
|
|
* pg_constraint definition. cpp turns this into
|
|
|
|
* typedef struct FormData_pg_constraint
|
|
|
|
* ----------------
|
|
|
|
*/
|
2005-04-14 03:38:22 +02:00
|
|
|
#define ConstraintRelationId 2606
|
|
|
|
|
|
|
|
CATALOG(pg_constraint,2606)
|
2002-07-12 20:43:19 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* conname + connamespace is deliberately not unique; we allow, for
|
|
|
|
* example, the same name to be used for constraints of different
|
|
|
|
* relations. This is partly for backwards compatibility with past
|
2005-10-15 04:49:52 +02:00
|
|
|
* Postgres practice, and partly because we don't want to have to obtain a
|
|
|
|
* global lock to generate a globally unique name for a nameless
|
|
|
|
* constraint. We associate a namespace with constraint names only for
|
2010-01-17 23:56:23 +01:00
|
|
|
* SQL-spec compatibility.
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
|
|
|
NameData conname; /* name of this constraint */
|
|
|
|
Oid connamespace; /* OID of namespace containing constraint */
|
|
|
|
char contype; /* constraint type; see codes below */
|
|
|
|
bool condeferrable; /* deferrable constraint? */
|
|
|
|
bool condeferred; /* deferred by default? */
|
2011-02-08 13:23:20 +01:00
|
|
|
bool convalidated; /* constraint has been validated? */
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* conrelid and conkey are only meaningful if the constraint applies to a
|
|
|
|
* specific relation (this excludes domain constraints and assertions).
|
|
|
|
* Otherwise conrelid is 0 and conkey is NULL.
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
|
|
|
Oid conrelid; /* relation this constraint constrains */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* contypid links to the pg_type row for a domain if this is a domain
|
2002-09-04 22:31:48 +02:00
|
|
|
* constraint. Otherwise it's 0.
|
2002-07-12 20:43:19 +02:00
|
|
|
*
|
2005-11-22 19:17:34 +01:00
|
|
|
* For SQL-style global ASSERTIONs, both conrelid and contypid would be
|
|
|
|
* zero. This is not presently supported, however.
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
|
|
|
Oid contypid; /* domain this constraint constrains */
|
|
|
|
|
2009-07-28 04:56:31 +02:00
|
|
|
/*
|
|
|
|
* conindid links to the index supporting the constraint, if any;
|
2010-03-11 04:36:22 +01:00
|
|
|
* otherwise it's 0. This is used for unique, primary-key, and exclusion
|
|
|
|
* constraints, and less obviously for foreign-key constraints (where the
|
|
|
|
* index is a unique index on the referenced relation's referenced
|
|
|
|
* columns). Notice that the index is on conrelid in the first case but
|
|
|
|
* confrelid in the second.
|
2009-07-28 04:56:31 +02:00
|
|
|
*/
|
|
|
|
Oid conindid; /* index supporting this constraint */
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/*
|
|
|
|
* These fields, plus confkey, are only meaningful for a foreign-key
|
2005-10-15 04:49:52 +02:00
|
|
|
* constraint. Otherwise confrelid is 0 and the char fields are spaces.
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
|
|
|
Oid confrelid; /* relation referenced by foreign key */
|
|
|
|
char confupdtype; /* foreign key's ON UPDATE action */
|
|
|
|
char confdeltype; /* foreign key's ON DELETE action */
|
|
|
|
char confmatchtype; /* foreign key's match type */
|
|
|
|
|
2008-05-10 01:32:05 +02:00
|
|
|
/* Has a local definition (hence, do not drop when coninhcount is 0) */
|
|
|
|
bool conislocal;
|
|
|
|
|
|
|
|
/* Number of times inherited from direct parent relation(s) */
|
2012-06-25 00:51:46 +02:00
|
|
|
int32 coninhcount;
|
2008-05-10 01:32:05 +02:00
|
|
|
|
2011-12-05 19:10:18 +01:00
|
|
|
/* Has a local definition and cannot be inherited */
|
2012-04-21 04:46:20 +02:00
|
|
|
bool connoinherit;
|
2011-12-05 19:10:18 +01:00
|
|
|
|
2012-01-27 19:16:17 +01:00
|
|
|
#ifdef CATALOG_VARLEN /* variable-length fields start here */
|
2012-06-10 21:20:04 +02:00
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/*
|
2010-02-26 03:01:40 +01:00
|
|
|
* Columns of conrelid that the constraint applies to, if known (this is
|
|
|
|
* NULL for trigger constraints)
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
2012-06-25 00:51:46 +02:00
|
|
|
int16 conkey[1];
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a foreign key, the referenced columns of confrelid
|
|
|
|
*/
|
2012-06-25 00:51:46 +02:00
|
|
|
int16 confkey[1];
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2007-02-14 02:58:58 +01:00
|
|
|
/*
|
|
|
|
* If a foreign key, the OIDs of the PK = FK equality operators for each
|
|
|
|
* column of the constraint
|
|
|
|
*/
|
|
|
|
Oid conpfeqop[1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a foreign key, the OIDs of the PK = PK equality operators for each
|
|
|
|
* column of the constraint (i.e., equality for the referenced columns)
|
|
|
|
*/
|
|
|
|
Oid conppeqop[1];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a foreign key, the OIDs of the FK = FK equality operators for each
|
|
|
|
* column of the constraint (i.e., equality for the referencing columns)
|
|
|
|
*/
|
|
|
|
Oid conffeqop[1];
|
|
|
|
|
2009-12-07 06:22:23 +01:00
|
|
|
/*
|
|
|
|
* If an exclusion constraint, the OIDs of the exclusion operators for
|
|
|
|
* each column of the constraint
|
|
|
|
*/
|
|
|
|
Oid conexclop[1];
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/*
|
|
|
|
* If a check constraint, nodeToString representation of expression
|
|
|
|
*/
|
2010-09-03 03:34:55 +02:00
|
|
|
pg_node_tree conbin;
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a check constraint, source-text representation of expression
|
|
|
|
*/
|
|
|
|
text consrc;
|
2012-01-27 19:16:17 +01:00
|
|
|
#endif
|
2002-07-12 20:43:19 +02:00
|
|
|
} FormData_pg_constraint;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* Form_pg_constraint corresponds to a pointer to a tuple with
|
|
|
|
* the format of pg_constraint relation.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef FormData_pg_constraint *Form_pg_constraint;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* compiler constants for pg_constraint
|
|
|
|
* ----------------
|
|
|
|
*/
|
2011-12-05 19:10:18 +01:00
|
|
|
#define Natts_pg_constraint 24
|
2002-07-12 20:43:19 +02:00
|
|
|
#define Anum_pg_constraint_conname 1
|
|
|
|
#define Anum_pg_constraint_connamespace 2
|
|
|
|
#define Anum_pg_constraint_contype 3
|
|
|
|
#define Anum_pg_constraint_condeferrable 4
|
|
|
|
#define Anum_pg_constraint_condeferred 5
|
2011-02-08 13:23:20 +01:00
|
|
|
#define Anum_pg_constraint_convalidated 6
|
|
|
|
#define Anum_pg_constraint_conrelid 7
|
|
|
|
#define Anum_pg_constraint_contypid 8
|
|
|
|
#define Anum_pg_constraint_conindid 9
|
|
|
|
#define Anum_pg_constraint_confrelid 10
|
|
|
|
#define Anum_pg_constraint_confupdtype 11
|
|
|
|
#define Anum_pg_constraint_confdeltype 12
|
|
|
|
#define Anum_pg_constraint_confmatchtype 13
|
|
|
|
#define Anum_pg_constraint_conislocal 14
|
|
|
|
#define Anum_pg_constraint_coninhcount 15
|
2012-04-21 04:46:20 +02:00
|
|
|
#define Anum_pg_constraint_connoinherit 16
|
2011-12-05 19:10:18 +01:00
|
|
|
#define Anum_pg_constraint_conkey 17
|
|
|
|
#define Anum_pg_constraint_confkey 18
|
|
|
|
#define Anum_pg_constraint_conpfeqop 19
|
|
|
|
#define Anum_pg_constraint_conppeqop 20
|
|
|
|
#define Anum_pg_constraint_conffeqop 21
|
|
|
|
#define Anum_pg_constraint_conexclop 22
|
|
|
|
#define Anum_pg_constraint_conbin 23
|
|
|
|
#define Anum_pg_constraint_consrc 24
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Valid values for contype */
|
|
|
|
#define CONSTRAINT_CHECK 'c'
|
|
|
|
#define CONSTRAINT_FOREIGN 'f'
|
|
|
|
#define CONSTRAINT_PRIMARY 'p'
|
|
|
|
#define CONSTRAINT_UNIQUE 'u'
|
2010-01-17 23:56:23 +01:00
|
|
|
#define CONSTRAINT_TRIGGER 't'
|
2009-12-07 06:22:23 +01:00
|
|
|
#define CONSTRAINT_EXCLUSION 'x'
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
|
|
|
|
* constants defined in parsenodes.h. Valid values for confmatchtype are
|
|
|
|
* the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
|
|
|
|
*/
|
|
|
|
|
2002-11-15 03:50:21 +01:00
|
|
|
/*
|
2004-06-10 19:56:03 +02:00
|
|
|
* Identify constraint type for lookup purposes
|
2002-11-15 03:50:21 +01:00
|
|
|
*/
|
2004-06-10 19:56:03 +02:00
|
|
|
typedef enum ConstraintCategory
|
2003-08-04 02:43:34 +02:00
|
|
|
{
|
2002-11-15 03:50:21 +01:00
|
|
|
CONSTRAINT_RELATION,
|
|
|
|
CONSTRAINT_DOMAIN,
|
2004-06-10 19:56:03 +02:00
|
|
|
CONSTRAINT_ASSERTION /* for future expansion */
|
|
|
|
} ConstraintCategory;
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes for functions in pg_constraint.c
|
|
|
|
*/
|
2002-09-04 22:31:48 +02:00
|
|
|
extern Oid CreateConstraintEntry(const char *constraintName,
|
|
|
|
Oid constraintNamespace,
|
|
|
|
char constraintType,
|
|
|
|
bool isDeferrable,
|
|
|
|
bool isDeferred,
|
2011-02-08 13:23:20 +01:00
|
|
|
bool isValidated,
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid relId,
|
|
|
|
const int16 *constraintKey,
|
|
|
|
int constraintNKeys,
|
|
|
|
Oid domainId,
|
2009-07-28 04:56:31 +02:00
|
|
|
Oid indexRelId,
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid foreignRelId,
|
|
|
|
const int16 *foreignKey,
|
2007-02-14 02:58:58 +01:00
|
|
|
const Oid *pfEqOp,
|
|
|
|
const Oid *ppEqOp,
|
|
|
|
const Oid *ffEqOp,
|
2002-09-04 22:31:48 +02:00
|
|
|
int foreignNKeys,
|
|
|
|
char foreignUpdateType,
|
|
|
|
char foreignDeleteType,
|
|
|
|
char foreignMatchType,
|
2009-12-07 06:22:23 +01:00
|
|
|
const Oid *exclOp,
|
2002-09-04 22:31:48 +02:00
|
|
|
Node *conExpr,
|
|
|
|
const char *conBin,
|
2008-05-10 01:32:05 +02:00
|
|
|
const char *conSrc,
|
|
|
|
bool conIsLocal,
|
2011-12-05 19:10:18 +01:00
|
|
|
int conInhCount,
|
2013-03-18 03:55:14 +01:00
|
|
|
bool conNoInherit,
|
|
|
|
bool is_internal);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
|
|
|
extern void RemoveConstraintById(Oid conId);
|
2008-01-17 19:56:54 +01:00
|
|
|
extern void RenameConstraintById(Oid conId, const char *newname);
|
2011-02-08 13:23:20 +01:00
|
|
|
extern void SetValidatedConstraintById(Oid conId);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2004-06-10 19:56:03 +02:00
|
|
|
extern bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId,
|
2004-08-29 07:07:03 +02:00
|
|
|
Oid objNamespace, const char *conname);
|
2004-06-10 19:56:03 +02:00
|
|
|
extern char *ChooseConstraintName(const char *name1, const char *name2,
|
2009-07-16 08:33:46 +02:00
|
|
|
const char *label, Oid namespaceid,
|
2004-08-29 07:07:03 +02:00
|
|
|
List *others);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2005-08-01 06:03:59 +02:00
|
|
|
extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
|
2013-05-29 22:58:43 +02:00
|
|
|
Oid newNspId, bool isType, ObjectAddresses *objsMoved);
|
Avoid repeated name lookups during table and index DDL.
If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts. At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.
This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older). In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches. A field has also been added
to the Constraint node (FkConstraint in 8.4). Third-party code calling
these functions or using the Constraint node will require updating.
Report by Andres Freund. Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.
Security: CVE-2014-0062
2014-02-17 15:33:31 +01:00
|
|
|
extern void get_constraint_relation_oids(Oid constraint_oid, Oid *conrelid, Oid *confrelid);
|
2012-04-03 07:11:51 +02:00
|
|
|
extern Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok);
|
|
|
|
extern Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok);
|
2005-08-01 06:03:59 +02:00
|
|
|
|
2010-08-07 04:44:09 +02:00
|
|
|
extern bool check_functional_grouping(Oid relid,
|
2011-04-10 17:42:00 +02:00
|
|
|
Index varno, Index varlevelsup,
|
|
|
|
List *grouping_columns,
|
|
|
|
List **constraintDeps);
|
2010-08-07 04:44:09 +02:00
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
#endif /* PG_CONSTRAINT_H */
|