pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: Richard van den Berg <richard.vandenberg@trust-factory.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Foreign key slows down copy/insert
Date: Thu, 14 Apr 2005 22:35:00 +0800
Message-ID: <425E7F94.4080602@familyhealth.com.au> (raw)
In-Reply-To: <425E7D96.6020201@trust-factory.com>
References: <425E6045.4060201@trust-factory.com>
	<425E792B.4020500@familyhealth.com.au>
	<425E7D96.6020201@trust-factory.com>

>> 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?

Yeah I think it uses a different query formulation...  Actually I only 
assume that deferred fk's don't use that - I guess your experiment 
proves that.

>> Well, that's what people do - even pg_dump will restore data and add 
>> the foreign key afterward...
> 
> If I have to go this route, is there a way of automatically dropping and 
> re-adding FKs? I can probably query pg_constraints and drop the 
> appropriate ones, but how do I re-add them after the copy/insert?

Actually, you can just "disable" them if you want to be really dirty :) 
  You have to be confident that the data you're inserting does satisfy 
the FK, however otherwise you can end up with invalid data.

To see how to do that, try pg_dump with --disable-triggers mode enabled. 
  Just do a data-only dump.

Chris



view thread (24+ messages)  latest in thread

Message-ID: <425E7F94.4080602@familyhealth.com.au>
Permalink:  ../425E7F94.4080602@familyhealth.com.au/
Also on:    postgresql.org/message-id/425E7F94.4080602@familyhealth.com.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: chriskl@familyhealth.com.au, richard.vandenberg@trust-factory.com
  Subject: Re: Foreign key slows down copy/insert
  In-Reply-To: <425E7F94.4080602@familyhealth.com.au>
  References: <425E6045.4060201@trust-factory.com> <425E792B.4020500@familyhealth.com.au> <425E7D96.6020201@trust-factory.com> <425E7F94.4080602@familyhealth.com.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox