X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9A43FDB31D for ; Sat, 29 Oct 2005 13:05:58 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 92205-01 for ; Sat, 29 Oct 2005 16:05:57 +0000 (GMT) Received: from candle.pha.pa.us (candle.pha.pa.us [64.139.89.126]) by svr1.postgresql.org (Postfix) with ESMTP id B3E35DB325 for ; Sat, 29 Oct 2005 13:05:56 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id j9TG5XX07593; Sat, 29 Oct 2005 12:05:33 -0400 (EDT) From: Bruce Momjian Message-Id: <200510291605.j9TG5XX07593@candle.pha.pa.us> Subject: Re: Effects of cascading references in foreign keys In-Reply-To: <20051029144835.GA21068@wolff.to> To: Bruno Wolff III Date: Sat, 29 Oct 2005 12:05:33 -0400 (EDT) Cc: Martin Lesser , pgsql-performance@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.014 required=5 tests=[AWL=0.014] X-Spam-Score: 0.014 X-Spam-Level: X-Archive-Number: 200510/455 X-Sequence-Number: 15223 Bruno Wolff III wrote: > On Sat, Oct 29, 2005 at 13:10:31 +0200, > Martin Lesser 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