Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7A00C475DDA for ; Tue, 31 Dec 2002 22:32:12 -0500 (EST) Received: from kaukau.mcs.vuw.ac.nz (kaukau.mcs.vuw.ac.nz [130.195.5.20]) by postgresql.org (Postfix) with ESMTP id 0D13F475B47 for ; Tue, 31 Dec 2002 22:32:10 -0500 (EST) Received: from devon.mcs.vuw.ac.nz (devon.mcs.vuw.ac.nz [130.195.5.109]) by kaukau.mcs.vuw.ac.nz (8.12.6/8.12.6) with ESMTP id h013WDC6008506 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT) for ; Wed, 1 Jan 2003 16:32:13 +1300 (NZDT) Received: from localhost (localhost [[UNIX: localhost]]) by devon.mcs.vuw.ac.nz (8.11.6/8.11.1) id h013WAc05325 for pgsql-performance@postgresql.org; Wed, 1 Jan 2003 16:32:10 +1300 (NZDT) Content-Type: text/plain; charset="us-ascii" From: Minghann Ho To: pgsql-performance@postgresql.org Subject: alter table TBL add constraint TBL_FK foreign key ... very slow Date: Wed, 1 Jan 2003 16:32:10 +1300 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200301011632.10433.Minghann.Ho@mcs.vuw.ac.nz> X-Scanned-By: MIMEDefang 2.24 (www . roaringpenguin . com / mimedefang) X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/229 X-Sequence-Number: 645 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