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

From John Smith
Subject Re: COPY with fk's slow
Date
Msg-id 20030206200602.57055.qmail@web40702.mail.yahoo.com
Whole thread Raw
In response to Re: COPY with fk's slow  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

Turns out there was a duplicate index (on the id column) in the parent table. Dropped it, readded the f/k and now copy takes 5-10 secs :).

John

 Tom Lane <tgl@sss.pgh.pa.us> wrote:

John Smith writes:
> I'm playing around with importing 10,000 records into a table with a single index and a single foreign key. COPY takes roughly 10 minutes(!). However, if I drop the foreign key, COPY takes a couple seconds, THEN adding the foreign key back 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



Do y ou Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now

pgsql-general by date:

Previous
From: "Alastair D'Silva"
Date:
Subject: Re: OT: This list is Razored
Next
From: Robert Treat
Date:
Subject: Re: user column name