Skip site navigation (1) Skip section navigation (2)

Re: Effects of cascading references in foreign keys

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Bruno Wolff III <bruno(at)wolff(dot)to>,Martin Lesser <ml-pgsql(at)bettercom(dot)de>,pgsql-performance(at)postgresql(dot)org
Subject: Re: Effects of cascading references in foreign keys
Date: 2005-10-29 16:05:27
Message-ID: 20051029160527.GA80135@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-performance
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 <mike(at)fuhr(dot)org> 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

In response to

Responses

pgsql-performance by date

Next:From: Bruce MomjianDate: 2005-10-29 16:05:33
Subject: Re: Effects of cascading references in foreign keys
Previous:From: Bruno Wolff IIIDate: 2005-10-29 14:49:47
Subject: Re: Effects of cascading references in foreign keys

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group