Re: COPY with fk's slow - Mailing list pgsql-general

From Tom Lane
Subject Re: COPY with fk's slow
Date
Msg-id 12040.1044541862@sss.pgh.pa.us
Whole thread Raw
In response to COPY with fk's slow  (John Smith <john_smith_45678@yahoo.com>)
Responses Re: COPY with fk's slow  (John Smith <john_smith_45678@yahoo.com>)
List pgsql-general
John Smith <john_smith_45678@yahoo.com> writes:
> I'm playing around with importing 10,000 records into a table with a single index and a single foreign key. COPY
takesroughly 10 minutes(!). However, if I drop the foreign key, COPY takes a couple seconds, THEN adding the foreign
keyback takes another few seconds. Any idea why COPY with a f/k takes so much longer? Any workarounds? Such as lock the
table,drop fk, copy, add fk, unlock? 

Sounds like you are getting a bad plan for the fk-checking query.  Are
the referencing and referenced columns exactly the same datatype?  Do
they both have indexes?

BTW, when experimenting with this, keep in mind that the backend caches
query plans for fk queries.  You'll typically need to start a fresh
connection after doing something that you hope will improve the plan.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How do I create an array?
Next
From: Serkan Bektaþ
Date:
Subject: FW: Webmin version 1.060 released