pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Minghann Ho <mho@mcs.vuw.ac.nz>
To: pgsql-performance@postgresql.org
To: pgsql-performance-owner@postgresql.org
To: pgsql-admin@postgresql.org
Subject: alter table TBL add constraint TBL_FK foreign key ... very slow
Date: Wed, 1 Jan 2003 16:38:06 +1300
Message-ID: <200301011638.06045.mho@mcs.vuw.ac.nz> (raw)

Hi all,

I've experienced very slow performance to add foreign key constraints using 
ALTER TABLE ADD CONSTRAINT FOREIGN KEY ...

After using COPY ... FROM to load the base tables, I started to build the 
referential integrity between tables.
I have 3 tables: T1 (6 million records), T2 (1.5 million records) and T3 (0.8 
million records).
One of the RI - foreign key (T1 -> T2) constraint took about 70 hrs to build.
The other RI - foreign key (T1 -> T3) constraint took about 200 hrs and yet 
completed!! (compound foreign key)

I tried to use small subset of the tables of T2 and T3 to do the testing.
An estimation show that it need about 960 hrs to build the RI - foreign key 
constraints on table T1 -> T3 !!!

I've read in the archives that some people suffered slow performance of this 
problem in Aug 2000, but there was no further information about the solution.

Please anyone who has experience in this issues can give me some hint. 

Thanks

Hans



view thread (4+ messages)  latest in thread

Message-ID: <200301011638.06045.mho@mcs.vuw.ac.nz>
Permalink:  ../200301011638.06045.mho@mcs.vuw.ac.nz/
Also on:    postgresql.org/message-id/200301011638.06045.mho@mcs.vuw.ac.nz

 · 

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: mho@mcs.vuw.ac.nz, pgsql-performance-owner@postgresql.org, pgsql-admin@postgresql.org
  Subject: Re: alter table TBL add constraint TBL_FK foreign key ... very slow
  In-Reply-To: <200301011638.06045.mho@mcs.vuw.ac.nz>
  References: <200301011638.06045.mho@mcs.vuw.ac.nz>

* 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