Re: [PERFORM] Foreign key performance

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Kevin Brown <kevin(at)sysexperts(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>, <pgsql-performance(at)postgresql(dot)org>
Subject: Re: [PERFORM] Foreign key performance
Date: 2003-04-18 05:30:45
Message-ID: 20030417222628.G97462-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

On Thu, 17 Apr 2003, Kevin Brown wrote:

> I have no problem with that under normal circumstances (i.e., the
> foreign key constraints are actively being enforced): it may well be
> the nature of foreign keys, but the problem is this: all the keys are
> DEFERRABLE INITIALLY DEFERRED and, on top of that, the Perl program
> will SET CONSTRAINTS ALL DEFERRED at the beginning of the transaction.
>
> If I remove all the foreign key constraints, my performance goes up to
> 700 inserts per second!
>
> Why isn't the insert performance with all the constraints deferred
> approximating that of the performance I get without the foreign keys??

It appears (from some not terribly scientific experiments - see below)
that it's likely to be related to managing the deferred trigger queue
given that in my case at least running the constraints non-deferred was
negligible in comparison.

On batch inserts to three tables each with a foreign key to a table
containing one row (and inserts of lots of that value), I saw a ratio of
approximately 1:1.7:7 for normal inserts:non-deferred fk:deferred fk on my
7.4 dev server.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-04-18 05:49:55 Re: Note about upcoming instability in FE/BE protocol
Previous Message Kevin Brown 2003-04-18 05:11:33 Foreign key performance

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2003-04-18 06:06:04 Re: [PERFORM] Foreign key performance
Previous Message Kevin Brown 2003-04-18 05:11:33 Foreign key performance