aboutsummaryrefslogtreecommitdiff
path: root/src/include/commands/trigger.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-02-14 01:58:58 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-02-14 01:58:58 +0000
commit7bddca3450cc8631e5bf05e43988cf10ae32230e (patch)
tree0bdc9972eb5c687d2dd6d266295de3d317dee229 /src/include/commands/trigger.h
parent65e2f55031802dd1ee8f22d880e49b94b3534483 (diff)
downloadpostgresql-7bddca3450cc8631e5bf05e43988cf10ae32230e.tar.gz
postgresql-7bddca3450cc8631e5bf05e43988cf10ae32230e.zip
Fix up foreign-key mechanism so that there is a sound semantic basis for the
equality checks it applies, instead of a random dependence on whatever operators might be named "=". The equality operators will now be selected from the opfamily of the unique index that the FK constraint depends on to enforce uniqueness of the referenced columns; therefore they are certain to be consistent with that index's notion of equality. Among other things this should fix the problem noted awhile back that pg_dump may fail for foreign-key constraints on user-defined types when the required operators aren't in the search path. This also means that the former warning condition about "foreign key constraint will require costly sequential scans" is gone: if the comparison condition isn't indexable then we'll reject the constraint entirely. All per past discussions. Along the way, make the RI triggers look into pg_constraint for their information, instead of using pg_trigger.tgargs; and get rid of the always error-prone fixed-size string buffers in ri_triggers.c in favor of building up the RI queries in StringInfo buffers. initdb forced due to columns added to pg_constraint and pg_trigger.
Diffstat (limited to 'src/include/commands/trigger.h')
-rw-r--r--src/include/commands/trigger.h36
1 files changed, 5 insertions, 31 deletions
diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h
index 284815b47f7..ac9eb7296d1 100644
--- a/src/include/commands/trigger.h
+++ b/src/include/commands/trigger.h
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.60 2007/01/05 22:19:54 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.61 2007/02/14 01:58:58 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -78,34 +78,8 @@ typedef struct TriggerData
#define TRIGGER_FIRED_AFTER(event) \
(!TRIGGER_FIRED_BEFORE (event))
-/*
- * RI trigger function arguments are stored in pg_trigger.tgargs bytea
- *
- * constrname\0fkrel\0pkrel\0matchtype\0fkatt\0pkatt\0fkatt\0pkatt\0...
- *
- * There are one or more pairs of fkatt/pkatt names.
- *
- * The relation names are no longer of much use since they are not
- * guaranteed unique; they are present only for backwards compatibility.
- * Use the tgrelid and tgconstrrelid fields to identify the referenced
- * relations, instead. (But note that which is which will depend on which
- * trigger you are looking at!)
- */
-#define RI_CONSTRAINT_NAME_ARGNO 0
-#define RI_FK_RELNAME_ARGNO 1
-#define RI_PK_RELNAME_ARGNO 2
-#define RI_MATCH_TYPE_ARGNO 3
-#define RI_FIRST_ATTNAME_ARGNO 4 /* first attname pair starts
- * here */
-
-#define RI_KEYPAIR_FK_IDX 0
-#define RI_KEYPAIR_PK_IDX 1
-
-#define RI_MAX_NUMKEYS INDEX_MAX_KEYS
-#define RI_MAX_ARGUMENTS (RI_FIRST_ATTNAME_ARGNO + (RI_MAX_NUMKEYS * 2))
-
-extern Oid CreateTrigger(CreateTrigStmt *stmt, bool forConstraint);
+extern Oid CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid);
extern void DropTrigger(Oid relid, const char *trigname,
DropBehavior behavior, bool missing_ok);
@@ -175,10 +149,10 @@ extern bool RI_FKey_keyequal_upd_pk(Trigger *trigger, Relation pk_rel,
HeapTuple old_row, HeapTuple new_row);
extern bool RI_FKey_keyequal_upd_fk(Trigger *trigger, Relation fk_rel,
HeapTuple old_row, HeapTuple new_row);
-extern bool RI_Initial_Check(FkConstraint *fkconstraint,
- Relation rel,
- Relation pkrel);
+extern bool RI_Initial_Check(Trigger *trigger,
+ Relation fk_rel, Relation pk_rel);
+/* result values for RI_FKey_trigger_type: */
#define RI_TRIGGER_PK 1 /* is a trigger on the PK relation */
#define RI_TRIGGER_FK 2 /* is a trigger on the FK relation */
#define RI_TRIGGER_NONE 0 /* is not an RI trigger function */