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 7B49BDB12E for ; Sat, 29 Oct 2005 13:05:56 -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 81596-09 for ; Sat, 29 Oct 2005 16:05:55 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 16428DB096 for ; Sat, 29 Oct 2005 13:05:54 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j9TG5UOD008791 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 29 Oct 2005 10:05:32 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id j9TG5TKr080223; Sat, 29 Oct 2005 10:05:30 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id j9TG5RtA080222; Sat, 29 Oct 2005 10:05:27 -0600 (MDT) (envelope-from mfuhr) Date: Sat, 29 Oct 2005 10:05:27 -0600 From: Michael Fuhr To: Bruno Wolff III , Martin Lesser , pgsql-performance@postgresql.org Subject: Re: Effects of cascading references in foreign keys Message-ID: <20051029160527.GA80135@winnie.fuhr.org> References: <87acgszihk.fsf@nb-aspire.bettercom.de> <20051029142432.GA79557@winnie.fuhr.org> <20051029144947.GB21068@wolff.to> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051029144947.GB21068@wolff.to> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006] X-Spam-Score: 0.006 X-Spam-Level: X-Archive-Number: 200510/454 X-Sequence-Number: 15222 On Sat, Oct 29, 2005 at 09:49:47AM -0500, Bruno Wolff III wrote: > On Sat, Oct 29, 2005 at 08:24:32 -0600, Michael Fuhr wrote: > > My tests suggest that a lookup on the referring key is done only > > if the referenced key is changed. Here's an example from 8.1beta4; > > I used this version because EXPLAIN ANALYZE shows triggers and the > > time spent in them, but I see similar performance characteristics > > in earlier versions. I've intentionally not put an index on the > > referring column to make lookups on it slow. > > It looks like this feature was added last May, so I think it only applies > to 8.1. Earlier versions appear to have at least some kind of optimization. Here's a test in 7.3.11 using the same tables I used in 8.1beta4, although on a slower box. test=> UPDATE foo SET x = 1 WHERE id = 100000; UPDATE 1 Time: 32.18 ms test=> UPDATE foo SET x = 1, id = 200000 WHERE id = 100000; UPDATE 1 Time: 4144.95 ms test=> DROP TABLE bar; DROP TABLE Time: 240.87 ms test=> UPDATE foo SET x = 1, id = 100000 WHERE id = 200000; UPDATE 1 Time: 63.52 ms -- Michael Fuhr