2002-07-12 20:43:19 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* dependency.h
|
|
|
|
* Routines to support inter-object dependencies.
|
|
|
|
*
|
|
|
|
*
|
2003-08-04 04:40:20 +02:00
|
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
2002-07-12 20:43:19 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2004-05-05 06:48:48 +02:00
|
|
|
* $PostgreSQL: pgsql/src/include/catalog/dependency.h,v 1.12 2004/05/05 04:48:47 tgl Exp $
|
2002-07-12 20:43:19 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef DEPENDENCY_H
|
|
|
|
#define DEPENDENCY_H
|
|
|
|
|
|
|
|
#include "nodes/parsenodes.h" /* for DropBehavior */
|
|
|
|
|
|
|
|
|
2004-05-05 06:48:48 +02:00
|
|
|
/*----------
|
2002-07-12 20:43:19 +02:00
|
|
|
* Precise semantics of a dependency relationship are specified by the
|
|
|
|
* DependencyType code (which is stored in a "char" field in pg_depend,
|
|
|
|
* so we assign ASCII-code values to the enumeration members).
|
|
|
|
*
|
|
|
|
* In all cases, a dependency relationship indicates that the referenced
|
|
|
|
* object may not be dropped without also dropping the dependent object.
|
|
|
|
* However, there are several subflavors:
|
|
|
|
*
|
|
|
|
* DEPENDENCY_NORMAL ('n'): normal relationship between separately-created
|
|
|
|
* objects. The dependent object may be dropped without affecting the
|
|
|
|
* referenced object. The referenced object may only be dropped by
|
|
|
|
* specifying CASCADE, in which case the dependent object is dropped too.
|
|
|
|
* Example: a table column has a normal dependency on its datatype.
|
|
|
|
*
|
|
|
|
* DEPENDENCY_AUTO ('a'): the dependent object can be dropped separately
|
|
|
|
* from the referenced object, and should be automatically dropped
|
|
|
|
* (regardless of RESTRICT or CASCADE mode) if the referenced object
|
|
|
|
* is dropped.
|
|
|
|
* Example: a named constraint on a table is made auto-dependent on
|
|
|
|
* the table, so that it will go away if the table is dropped.
|
|
|
|
*
|
|
|
|
* DEPENDENCY_INTERNAL ('i'): the dependent object was created as part
|
|
|
|
* of creation of the referenced object, and is really just a part of
|
|
|
|
* its internal implementation. A DROP of the dependent object will be
|
|
|
|
* disallowed outright (we'll tell the user to issue a DROP against the
|
|
|
|
* referenced object, instead). A DROP of the referenced object will be
|
|
|
|
* propagated through to drop the dependent object whether CASCADE is
|
|
|
|
* specified or not.
|
|
|
|
* Example: a trigger that's created to enforce a foreign-key constraint
|
|
|
|
* is made internally dependent on the constraint's pg_constraint entry.
|
|
|
|
*
|
|
|
|
* DEPENDENCY_PIN ('p'): there is no dependent object; this type of entry
|
|
|
|
* is a signal that the system itself depends on the referenced object,
|
|
|
|
* and so that object must never be deleted. Entries of this type are
|
2002-09-04 22:31:48 +02:00
|
|
|
* created only during initdb. The fields for the dependent object
|
2002-07-12 20:43:19 +02:00
|
|
|
* contain zeroes.
|
|
|
|
*
|
|
|
|
* Other dependency flavors may be needed in future.
|
2004-05-05 06:48:48 +02:00
|
|
|
*----------
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
typedef enum DependencyType
|
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
DEPENDENCY_NORMAL = 'n',
|
|
|
|
DEPENDENCY_AUTO = 'a',
|
|
|
|
DEPENDENCY_INTERNAL = 'i',
|
|
|
|
DEPENDENCY_PIN = 'p'
|
2002-07-12 20:43:19 +02:00
|
|
|
} DependencyType;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The two objects related by a dependency are identified by ObjectAddresses.
|
|
|
|
*/
|
|
|
|
typedef struct ObjectAddress
|
|
|
|
{
|
2002-09-04 22:31:48 +02:00
|
|
|
Oid classId; /* Class Id from pg_class */
|
|
|
|
Oid objectId; /* OID of the object */
|
|
|
|
int32 objectSubId; /* Subitem within the object (column of
|
|
|
|
* table) */
|
2002-07-12 20:43:19 +02:00
|
|
|
} ObjectAddress;
|
|
|
|
|
|
|
|
|
2004-05-05 06:48:48 +02:00
|
|
|
/*
|
|
|
|
* This enum covers all system catalogs whose OIDs can appear in classId.
|
|
|
|
*/
|
|
|
|
typedef enum ObjectClass
|
|
|
|
{
|
|
|
|
OCLASS_CLASS, /* pg_class */
|
|
|
|
OCLASS_PROC, /* pg_proc */
|
|
|
|
OCLASS_TYPE, /* pg_type */
|
|
|
|
OCLASS_CAST, /* pg_cast */
|
|
|
|
OCLASS_CONSTRAINT, /* pg_constraint */
|
|
|
|
OCLASS_CONVERSION, /* pg_conversion */
|
|
|
|
OCLASS_DEFAULT, /* pg_attrdef */
|
|
|
|
OCLASS_LANGUAGE, /* pg_language */
|
|
|
|
OCLASS_OPERATOR, /* pg_operator */
|
|
|
|
OCLASS_OPCLASS, /* pg_opclass */
|
|
|
|
OCLASS_REWRITE, /* pg_rewrite */
|
|
|
|
OCLASS_TRIGGER, /* pg_trigger */
|
|
|
|
OCLASS_SCHEMA, /* pg_namespace */
|
|
|
|
MAX_OCLASS /* MUST BE LAST */
|
|
|
|
} ObjectClass;
|
|
|
|
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/* in dependency.c */
|
|
|
|
|
|
|
|
extern void performDeletion(const ObjectAddress *object,
|
2002-09-04 22:31:48 +02:00
|
|
|
DropBehavior behavior);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2003-03-06 23:54:49 +01:00
|
|
|
extern void deleteWhatDependsOn(const ObjectAddress *object,
|
2003-08-04 02:43:34 +02:00
|
|
|
bool showNotices);
|
2003-02-07 02:33:06 +01:00
|
|
|
|
2002-07-16 07:53:34 +02:00
|
|
|
extern void recordDependencyOnExpr(const ObjectAddress *depender,
|
2002-09-04 22:31:48 +02:00
|
|
|
Node *expr, List *rtable,
|
|
|
|
DependencyType behavior);
|
2002-07-16 07:53:34 +02:00
|
|
|
|
2003-05-28 18:04:02 +02:00
|
|
|
extern void recordDependencyOnSingleRelExpr(const ObjectAddress *depender,
|
2003-08-04 02:43:34 +02:00
|
|
|
Node *expr, Oid relId,
|
|
|
|
DependencyType behavior,
|
|
|
|
DependencyType self_behavior);
|
2003-05-28 18:04:02 +02:00
|
|
|
|
2004-05-05 06:48:48 +02:00
|
|
|
extern ObjectClass getObjectClass(const ObjectAddress *object);
|
|
|
|
|
|
|
|
extern char *getObjectDescription(const ObjectAddress *object);
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/* in pg_depend.c */
|
|
|
|
|
|
|
|
extern void recordDependencyOn(const ObjectAddress *depender,
|
2002-09-04 22:31:48 +02:00
|
|
|
const ObjectAddress *referenced,
|
|
|
|
DependencyType behavior);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2002-07-16 07:53:34 +02:00
|
|
|
extern void recordMultipleDependencies(const ObjectAddress *depender,
|
2002-09-04 22:31:48 +02:00
|
|
|
const ObjectAddress *referenced,
|
|
|
|
int nreferenced,
|
|
|
|
DependencyType behavior);
|
2002-07-16 07:53:34 +02:00
|
|
|
|
2002-08-11 23:17:35 +02:00
|
|
|
extern long deleteDependencyRecordsFor(Oid classId, Oid objectId);
|
2002-07-17 00:12:20 +02:00
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
#endif /* DEPENDENCY_H */
|