pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PFC <lists@boutiquenumerique.com>
To: Richard van den Berg <richard.vandenberg@trust-factory.com>
To: pgsql-performance@postgresql.org
Subject: Re: Foreign key slows down copy/insert
Date: Thu, 14 Apr 2005 19:22:19 +0200
Message-ID: <op.so8fvhlwth1vuj@localhost> (raw)
In-Reply-To: <425E6045.4060201@trust-factory.com>
References: <425E6045.4060201@trust-factory.com>


> I have a table A with an int column ID that references table B column
> ID. Table B has about 150k rows, and has an index on B.ID. When trying
> to copy 1 million rows into A, I get the following \timings:

	You're using 7.4.5. It's possible that you have a type mismatch in your  
foreign keys which prevents use of the index on B.
	First of all, be really sure it's THAT foreign key, ie. do your COPY with  
only ONE foreign key at a time if you have several, and see which one is  
the killer.

	Then, supposing it's the column in A which REFERENCE's B(id) :

	SELECT id FROM A LIMIT 1;
	(check type)

	SELECT id FROM B LIMIT 1;
	(check type)

	EXPLAIN ANALYZE the following :

	SELECT * FROM B WHERE id = (SELECT id FROM A LIMIT 1);

	It should use the index. Does it ?




view thread (24+ messages)  latest in thread

Message-ID: <op.so8fvhlwth1vuj@localhost>
Permalink:  ../op.so8fvhlwth1vuj@localhost/
Also on:    postgresql.org/message-id/op.so8fvhlwth1vuj@localhost

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: lists@boutiquenumerique.com, richard.vandenberg@trust-factory.com
  Subject: Re: Foreign key slows down copy/insert
  In-Reply-To: <op.so8fvhlwth1vuj@localhost>

* 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