Re: Foreign key slows down copy/insert

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Richard van den Berg <richard(dot)vandenberg(at)trust-factory(dot)com>
Cc: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Foreign key slows down copy/insert
Date: 2005-04-14 14:45:33
Message-ID: 20050414074154.M38465@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On Thu, 14 Apr 2005, Richard van den Berg wrote:

> Hello Chris,
>
> Thanks for your answers.
>
> Christopher Kings-Lynne wrote:
> > Deferring makes no difference to FK checking speed...
>
> But why then is the speed acceptable if I copy and then manually add the
> FK? Is the check done by the FK so much different from when it is done
> automatically using an active deffered FK?

Yes, because currently the check done by the FK on an insert type activity
is a per-row inserted check while the check done when adding a FK acts on
the entire table in a go which allows better optimization of that case
(while generally being worse on small number inserts especially on large
tables). At some point, if we can work out how to do all the semantics
properly, it'd probably be possible to replace the insert type check with
a per-statement check which would be somewhere in between. That requires
access to the affected rows inside the trigger which I don't believe is
available currently.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Joel Fradkin 2005-04-14 14:45:48 Re: speed of querry?
Previous Message Tom Lane 2005-04-14 14:44:14 Re: How to improve db performance with $7K?