From adfeef55cbcc5dc72a772777f88c1be05a70dfee Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Mon, 30 May 2005 07:20:59 +0000 Subject: When enqueueing after-row triggers for updates of a table with a foreign key, compare the new and old row versions. If the foreign key column has not changed, we needn't enqueue the trigger, since the update cannot violate the foreign key. This optimization was previously applied in the RI trigger function, but it is more efficient to avoid firing the trigger altogether. Per recent discussion on pgsql-hackers. Also add a regression test for some unintuitive foreign key behavior, and refactor some code that deals with the OIDs of the various RI trigger functions. --- src/include/commands/trigger.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/include/commands/trigger.h') diff --git a/src/include/commands/trigger.h b/src/include/commands/trigger.h index 81a665e2476..f6c1f88480b 100644 --- a/src/include/commands/trigger.h +++ b/src/include/commands/trigger.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.53 2005/04/11 19:51:15 tgl Exp $ + * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.54 2005/05/30 07:20:58 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -168,9 +168,18 @@ extern void AfterTriggerSetState(ConstraintsSetStmt *stmt); /* * in utils/adt/ri_triggers.c */ -extern bool RI_FKey_keyequal_upd(TriggerData *trigdata); +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); +#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 */ + +extern int RI_FKey_trigger_type(Oid tgfoid); + #endif /* TRIGGER_H */ -- cgit v1.2.3