pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard van den Berg <richard.vandenberg@trust-factory.com>
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
Cc: pgsql-performance@postgresql.org
Subject: Re: Foreign key slows down copy/insert
Date: Thu, 14 Apr 2005 17:08:22 +0200
Message-ID: <425E8766.8070901@trust-factory.com> (raw)
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>

Christopher Kings-Lynne wrote:
>> 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.

In my tests deferred or not deferred makes no difference in speed. I am 
still quite surprised by how huge the difference is.. this makes FKs 
quite unusable when added a lot of data to a table.


> Actually, you can just "disable" them if you want to be really dirty :) 

Thanks for the pointer. I got this from the archives:

------------------------
update pg_class set reltriggers=0 where relname = 'YOUR_TABLE_NAME';

to enable them after you are done, do

update pg_class set reltriggers = count(*) from pg_trigger where 
pg_class.oid=tgrelid and relname='YOUR_TABLE_NAME';
------------------------

I assume the re-enabling will cause an error when the copy/insert added 
data that does not satisfy the FK. In that case I'll indeed end up with 
invalid data, but at least I will know about it.

Thanks,

-- 
Richard van den Berg, CISSP
-------------------------------------------
Trust Factory B.V. |     www.dna-portal.net
Bazarstraat 44a    |  www.trust-factory.com
2518AK The Hague   |  Phone: +31 70 3620684
The Netherlands    |  Fax  : +31 70 3603009
-------------------------------------------



view thread (24+ messages)  latest in thread

Message-ID: <425E8766.8070901@trust-factory.com>
Permalink:  ../425E8766.8070901@trust-factory.com/
Also on:    postgresql.org/message-id/425E8766.8070901@trust-factory.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: richard.vandenberg@trust-factory.com, chriskl@familyhealth.com.au
  Subject: Re: Foreign key slows down copy/insert
  In-Reply-To: <425E8766.8070901@trust-factory.com>

* 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