aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-01-17 22:56:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-01-17 22:56:23 +0000
commit9a915e596f38a97f10e00d388f18e178136937eb (patch)
treec0f85775a2423e0fb28c4d96d85569781668011e /src/include
parentee3b4188a78916544ef30e93fc1c9e5e780e07d5 (diff)
downloadpostgresql-9a915e596f38a97f10e00d388f18e178136937eb.tar.gz
postgresql-9a915e596f38a97f10e00d388f18e178136937eb.zip
Improve the handling of SET CONSTRAINTS commands by having them search
pg_constraint before searching pg_trigger. This allows saner handling of corner cases; in particular we now say "constraint is not deferrable" rather than "constraint does not exist" when the command is applied to a constraint that's inherently non-deferrable. Per a gripe several months ago from hubert depesz lubaczewski. To make this work without breaking user-defined constraint triggers, we have to add entries for them to pg_constraint. However, in return we can remove the pgconstrname column from pg_constraint, which represents a fairly sizable space savings. I also replaced the tgisconstraint column with tgisinternal; the old meaning of tgisconstraint can now be had by testing for nonzero tgconstraint, while there is no other way to get the old meaning of nonzero tgconstraint, namely that the trigger was internally generated rather than being user-created. In passing, fix an old misstatement in the docs and comments, namely that pg_trigger.tgdeferrable is exactly redundant with pg_constraint.condeferrable. Actually, we mark RI action triggers as nondeferrable even when they belong to a nominally deferrable FK constraint. The SET CONSTRAINTS code now relies on that instead of hard-coding a list of exception OIDs.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/catalog/catversion.h4
-rw-r--r--src/include/catalog/indexing.h6
-rw-r--r--src/include/catalog/pg_constraint.h8
-rw-r--r--src/include/catalog/pg_trigger.h39
-rw-r--r--src/include/commands/trigger.h6
-rw-r--r--src/include/nodes/parsenodes.h5
-rw-r--r--src/include/utils/rel.h4
7 files changed, 35 insertions, 37 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h
index b2c92860f07..1740b2b38c4 100644
--- a/src/include/catalog/catversion.h
+++ b/src/include/catalog/catversion.h
@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.573 2010/01/15 09:19:07 heikki Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.574 2010/01/17 22:56:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -53,6 +53,6 @@
*/
/* yyyymmddN */
-#define CATALOG_VERSION_NO 201001151
+#define CATALOG_VERSION_NO 201001171
#endif
diff --git a/src/include/catalog/indexing.h b/src/include/catalog/indexing.h
index 6bbb6f71926..0d29875e52e 100644
--- a/src/include/catalog/indexing.h
+++ b/src/include/catalog/indexing.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/indexing.h,v 1.115 2010/01/05 01:06:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/indexing.h,v 1.116 2010/01/17 22:56:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -220,8 +220,8 @@ DECLARE_UNIQUE_INDEX(pg_tablespace_spcname_index, 2698, on pg_tablespace using b
#define TablespaceNameIndexId 2698
/* This following index is not used for a cache and is not unique */
-DECLARE_INDEX(pg_trigger_tgconstrname_index, 2699, on pg_trigger using btree(tgconstrname name_ops));
-#define TriggerConstrNameIndexId 2699
+DECLARE_INDEX(pg_trigger_tgconstraint_index, 2699, on pg_trigger using btree(tgconstraint oid_ops));
+#define TriggerConstraintIndexId 2699
DECLARE_UNIQUE_INDEX(pg_trigger_tgrelid_tgname_index, 2701, on pg_trigger using btree(tgrelid oid_ops, tgname name_ops));
#define TriggerRelidNameIndexId 2701
DECLARE_UNIQUE_INDEX(pg_trigger_oid_index, 2702, on pg_trigger using btree(oid oid_ops));
diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h
index 4242b24c0e1..1aada159dbb 100644
--- a/src/include/catalog/pg_constraint.h
+++ b/src/include/catalog/pg_constraint.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/pg_constraint.h,v 1.36 2010/01/05 01:06:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_constraint.h,v 1.37 2010/01/17 22:56:23 tgl Exp $
*
* NOTES
* the genbki.pl script reads this file and generates .bki
@@ -38,7 +38,7 @@ CATALOG(pg_constraint,2606)
* 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
- * SQL92 compatibility.
+ * SQL-spec compatibility.
*/
NameData conname; /* name of this constraint */
Oid connamespace; /* OID of namespace containing constraint */
@@ -92,7 +92,8 @@ CATALOG(pg_constraint,2606)
*/
/*
- * Columns of conrelid that the constraint applies to
+ * Columns of conrelid that the constraint applies to, if known
+ * (this is NULL for trigger constraints)
*/
int2 conkey[1];
@@ -177,6 +178,7 @@ typedef FormData_pg_constraint *Form_pg_constraint;
#define CONSTRAINT_FOREIGN 'f'
#define CONSTRAINT_PRIMARY 'p'
#define CONSTRAINT_UNIQUE 'u'
+#define CONSTRAINT_TRIGGER 't'
#define CONSTRAINT_EXCLUSION 'x'
/*
diff --git a/src/include/catalog/pg_trigger.h b/src/include/catalog/pg_trigger.h
index 8e1a4bf12b7..7c954750433 100644
--- a/src/include/catalog/pg_trigger.h
+++ b/src/include/catalog/pg_trigger.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/pg_trigger.h,v 1.38 2010/01/05 01:06:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_trigger.h,v 1.39 2010/01/17 22:56:23 tgl Exp $
*
* NOTES
* the genbki.pl script reads this file and generates .bki
@@ -25,11 +25,10 @@
* pg_trigger definition. cpp turns this into
* typedef struct FormData_pg_trigger
*
- * Note: when tgconstraint is nonzero, tgisconstraint must be true, and
- * tgconstrname, tgconstrrelid, tgconstrindid, tgdeferrable, tginitdeferred
- * are redundant with the referenced pg_constraint entry. The reason we keep
- * these fields is that we support "stand-alone" constraint triggers with no
- * corresponding pg_constraint entry.
+ * Note: when tgconstraint is nonzero, tgconstrrelid, tgconstrindid,
+ * tgdeferrable, and tginitdeferred are largely redundant with the referenced
+ * pg_constraint entry. However, it is possible for a non-deferrable trigger
+ * to be associated with a deferrable constraint.
* ----------------
*/
#define TriggerRelationId 2620
@@ -43,11 +42,10 @@ CATALOG(pg_trigger,2620)
* ROW/STATEMENT; see below */
char tgenabled; /* trigger's firing configuration WRT
* session_replication_role */
- bool tgisconstraint; /* trigger is a constraint trigger */
- NameData tgconstrname; /* constraint name */
+ bool tgisinternal; /* trigger is system-generated */
Oid tgconstrrelid; /* constraint's FROM table, if any */
Oid tgconstrindid; /* constraint's supporting index, if any */
- Oid tgconstraint; /* owning pg_constraint entry, if any */
+ Oid tgconstraint; /* associated pg_constraint entry, if any */
bool tgdeferrable; /* constraint trigger is deferrable */
bool tginitdeferred; /* constraint trigger is deferred initially */
int2 tgnargs; /* # of extra arguments in tgargs */
@@ -69,23 +67,22 @@ typedef FormData_pg_trigger *Form_pg_trigger;
* compiler constants for pg_trigger
* ----------------
*/
-#define Natts_pg_trigger 16
+#define Natts_pg_trigger 15
#define Anum_pg_trigger_tgrelid 1
#define Anum_pg_trigger_tgname 2
#define Anum_pg_trigger_tgfoid 3
#define Anum_pg_trigger_tgtype 4
#define Anum_pg_trigger_tgenabled 5
-#define Anum_pg_trigger_tgisconstraint 6
-#define Anum_pg_trigger_tgconstrname 7
-#define Anum_pg_trigger_tgconstrrelid 8
-#define Anum_pg_trigger_tgconstrindid 9
-#define Anum_pg_trigger_tgconstraint 10
-#define Anum_pg_trigger_tgdeferrable 11
-#define Anum_pg_trigger_tginitdeferred 12
-#define Anum_pg_trigger_tgnargs 13
-#define Anum_pg_trigger_tgattr 14
-#define Anum_pg_trigger_tgargs 15
-#define Anum_pg_trigger_tgqual 16
+#define Anum_pg_trigger_tgisinternal 6
+#define Anum_pg_trigger_tgconstrrelid 7
+#define Anum_pg_trigger_tgconstrindid 8
+#define Anum_pg_trigger_tgconstraint 9
+#define Anum_pg_trigger_tgdeferrable 10
+#define Anum_pg_trigger_tginitdeferred 11
+#define Anum_pg_trigger_tgnargs 12
+#define Anum_pg_trigger_tgattr 13
+#define Anum_pg_trigger_tgargs 14
+#define Anum_pg_trigger_tgqual 15
/* Bits within tgtype */
#define TRIGGER_TYPE_ROW (1 << 0)
diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h
index b5f44bb33e1..db79eb4be73 100644
--- a/src/include/commands/trigger.h
+++ b/src/include/commands/trigger.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.79 2010/01/02 16:58:03 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.80 2010/01/17 22:56:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -105,8 +105,8 @@ extern PGDLLIMPORT int SessionReplicationRole;
#define TRIGGER_DISABLED 'D'
extern Oid CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
- Oid constraintOid, Oid indexOid, const char *prefix,
- bool checkPermissions);
+ Oid constraintOid, Oid indexOid,
+ bool isInternal);
extern void DropTrigger(Oid relid, const char *trigname,
DropBehavior behavior, bool missing_ok);
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index a03597c9f37..c752d071d52 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.424 2010/01/15 22:36:35 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.425 2010/01/17 22:56:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1593,9 +1593,8 @@ typedef struct CreateTrigStmt
int16 events; /* INSERT/UPDATE/DELETE/TRUNCATE */
List *columns; /* column names, or NIL for all columns */
Node *whenClause; /* qual expression, or NULL if none */
-
- /* The following are used for constraint triggers (RI and unique checks) */
bool isconstraint; /* This is a constraint trigger */
+ /* The remaining fields are only used for constraint triggers */
bool deferrable; /* [NOT] DEFERRABLE */
bool initdeferred; /* INITIALLY {DEFERRED|IMMEDIATE} */
RangeVar *constrrel; /* opposite relation, if RI trigger */
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index 250a127ed31..344f37a6872 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.119 2010/01/10 22:19:17 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.120 2010/01/17 22:56:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -56,7 +56,7 @@ typedef struct Trigger
Oid tgfoid;
int16 tgtype;
char tgenabled;
- bool tgisconstraint;
+ bool tgisinternal;
Oid tgconstrrelid;
Oid tgconstrindid;
Oid tgconstraint;