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: pgsql-performance@postgresql.org
Subject: Foreign key slows down copy/insert
Date: Thu, 14 Apr 2005 13:59:52 +0200
Message-ID: <425E5B38.6020407@trust-factory.com> (raw)

I am new to cross references between tables, and I am trying to 
understand how they impact performance. From reading the documentation I 
was under the impression that deffering foreign keys would yield about 
the same performance as dropping them before a copy, and adding them 
after. However, I cannot see this in my test case.

I have a table A with an int column ID that references table B column 
ID. Table B has about 150k rows, and has an index on B.ID. When trying 
to copy 1 million rows into A, I get the following \timings:

1) drop FK, copy (200s), add FK (5s)
2) add FK defferable initially deffered, copy (I aborted after 30min)
3) add FK defferable initially deffered, begin, copy (200s), commit (I 
aborted after 30min)

How do I explain why test cases 2 and 3 do not come close to case 1? Am 
I missing something obvious?

Since the database I am working on has many FKs, I would rather not have 
to drop/add them when I am loading large data sets.

If it would help I can write this out in a reproducable scenario. I am 
using postgresql 7.4.5 at the moment.

Sincerely,

-- 
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: <425E5B38.6020407@trust-factory.com>
Permalink:  ../425E5B38.6020407@trust-factory.com/
Also on:    postgresql.org/message-id/425E5B38.6020407@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
  Subject: Re: Foreign key slows down copy/insert
  In-Reply-To: <425E5B38.6020407@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