alter table TBL add constraint TBL_FK foreign key ... very slow

From: Minghann Ho <Minghann(dot)Ho(at)mcs(dot)vuw(dot)ac(dot)nz>
To: pgsql-performance(at)postgresql(dot)org
Subject: alter table TBL add constraint TBL_FK foreign key ... very slow
Date: 2003-01-01 03:32:10
Message-ID: 200301011632.10433.Minghann.Ho@mcs.vuw.ac.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

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

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Minghann Ho 2003-01-01 03:38:06 alter table TBL add constraint TBL_FK foreign key ... very slow
Previous Message Neil Conway 2002-12-31 23:05:27 Re: preliminary testing, two very slow situations...