From: Greg Stark <gsstark@mit.edu>
To: bsamwel@xs4all.nl
Cc: pgsql-performance@postgresql.org
Subject: Re: Adding a foreign key constraint is extremely slow
Date: 26 Mar 2003 09:17:47 -0500
Message-ID: <874r5qmctw.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <20505.194.109.187.67.1048442304.squirrel@webmail.xs4all.nl>
References: <20505.194.109.187.67.1048442304.squirrel@webmail.xs4all.nl>
bsamwel@xs4all.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
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: gsstark@mit.edu, bsamwel@xs4all.nl
Subject: Re: Adding a foreign key constraint is extremely slow
In-Reply-To: <874r5qmctw.fsf@stark.dyndns.tv>
References: <20505.194.109.187.67.1048442304.squirrel@webmail.xs4all.nl> <874r5qmctw.fsf@stark.dyndns.tv>
* 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