From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Bruno Wolff III <bruno@wolff.to>
Cc: Martin Lesser <ml-pgsql@bettercom.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Effects of cascading references in foreign keys
Date: Sat, 29 Oct 2005 12:05:33 -0400 (EDT)
Message-ID: <200510291605.j9TG5XX07593@candle.pha.pa.us> (raw)
In-Reply-To: <20051029144835.GA21068@wolff.to>
Bruno Wolff III wrote:
> On Sat, Oct 29, 2005 at 13:10:31 +0200,
> Martin Lesser <ml-pgsql@bettercom.de> wrote:
> > Which effects have UPDATEs on REFERENCEd TABLEs when only columns in the
> > referenced table are updated which are not part of the FOREIGN KEY
> > constraint?
>
> In 8.1 there is a check to see if the foreign key value has changed and if
> not a trigger isn't queued. In the currently released versions any update
> will fire triggers.
> The check in comment for trigger.c didn't say if this optimization applied
> to both referencing and referenced keys or just one of those.
> If you need to know more you can look at the code at:
> http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/
> for trigger.c.
It applies to both. See
src/backend/utils/adt/ri_triggers.c::RI_FKey_keyequal_upd_pk() and
RI_FKey_keyequal_upd_fk(). The first is for primary keys (pk), the
second for foreign keys (fk). These are called by
src/backend/command/triggers.c::AfterTriggerSaveEvent(). The checks
prevent the trigger from being registered at all if there is no change
in the primary/foreign key relationship.
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: pgman@candle.pha.pa.us, bruno@wolff.to, ml-pgsql@bettercom.de
Subject: Re: Effects of cascading references in foreign keys
In-Reply-To: <200510291605.j9TG5XX07593@candle.pha.pa.us>
References: <20051029144835.GA21068@wolff.to> <200510291605.j9TG5XX07593@candle.pha.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox