Re: on update / on delete performance of foreign keys

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: hf1122x(at)protecting(dot)net
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: on update / on delete performance of foreign keys
Date: 2005-01-24 18:40:19
Message-ID: 23502.1106592019@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Harald Fuchs <hf0722x(at)protecting(dot)net> writes:
> "Florian G. Pflug" <fgp(at)phlo(dot)org> writes:
>>> PostgreSQL doesn't automatically add indexes to foreign-key
>>> columns. That sounds like the issue to me.

>> Oh... *feeling a bit stupid*... Seems that I got confused, because it
>> requires an index to exist on the referenced table (To speed up inserts,
>> updates), but not on the referencing table...

> That's not quite right. What PostgreSQL (or any other DBMS) requires
> from the referenced table is a UNIQUE constraint on the column in
> question so that the referencing table points to a single row, and
> UNIQUE constraints are usually implemented by indices.

You missed the point. PG does force you to put an index on the
referenced column, but it does not force you to put one on the
referencing column. However, deletions in the referenced table are
going to be really slow if there is no index on the referencing column,
because there's no fast way to look up referencing rows matching the
key to be deleted.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Terry Lee Tucker 2005-01-24 18:45:11 Re: disable trigger from transaction
Previous Message Christoffer Gurell 2005-01-24 18:38:16 Re: number of rown in a cursor.