Skip site navigation (1) Skip section navigation (2)

Re: Adding a foreign key constraint is extremely slow

From: Greg Stark <gsstark(at)mit(dot)edu>
To: bsamwel(at)xs4all(dot)nl
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Adding a foreign key constraint is extremely slow
Date: 2003-03-26 14:17:47
Message-ID: 874r5qmctw.fsf@stark.dyndns.tv (view raw or flat)
Thread:
Lists: pgsql-performance
bsamwel(at)xs4all(dot)nl writes:

> alter table triples add foreign key(id1) references wwwlog(id);
> 
> PostgreSQL starts doing heavy work for at least one and a half hour, and I
> broke it off at that. It is not possible to "explain" a statement like
> this! Probably what it does is that it will check the foreign key
> constraint for every field in the table. This will make it completely
> impossible to load my data, because:
> 
> (2) I cannot set the foreign key constraints AFTER loading the 0.9 million
> records because I've got no clue at all how long this operation is going
> to take.

Try adding an index on wwwlog(id) so that it can check the constraint without
doing a full table scan for each value being checked.

-- 
greg


In response to

Responses

pgsql-performance by date

Next:From: Bart SamwelDate: 2003-03-26 17:08:51
Subject: Re: Adding a foreign key constraint is extremely slow
Previous:From: dharanaDate: 2003-03-25 20:32:04
Subject:

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group