Re: How are foreign key constraints built? - Mailing list pgsql-general

From Tom Lane
Subject Re: How are foreign key constraints built?
Date
Msg-id 5442.1106506901@sss.pgh.pa.us
Whole thread Raw
In response to How are foreign key constraints built?  (Wes <wespvp@syntegra.com>)
Responses Re: How are foreign key constraints built?  ("Jim C. Nasby" <decibel@decibel.org>)
Re: How are foreign key constraints built?  (Wes <wespvp@syntegra.com>)
List pgsql-general
Wes <wespvp@syntegra.com> writes:
> There's no problem here, I'd just like to understand what it is doing.

Either a hash or merge join between the two tables, to verify that all
the keys in the referencing table exist in the referenced table.  The
intermediate data is evidently spilling to disk.

> I expected adding the foreign key constraint would just use the existing
> indexes to verify the database is currently consistent.

People have this weird notion that an index-based plan is always faster
than anything else.  If you like you can try the operation with "set
enable_seqscan = off", but I bet it will take longer.

            regards, tom lane

pgsql-general by date:

Previous
From: Wes
Date:
Subject: How are foreign key constraints built?
Next
From: Jarkko Elfving
Date:
Subject: Re: Dead-end in PostgreSQL 8.0 fresh installation (while