Re: Foreign key / performance question

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Nico Callewaert <nico_callewaert(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Foreign key / performance question
Date: 2006-03-29 18:22:49
Message-ID: 20060329101752.I85958@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 29 Mar 2006, Nico Callewaert wrote:

> Is it wise to define foreign keys for referential entegrity ?

> Example : I have a customer table with 40 fields. Out of that 40
> fields, 10 fields contain information linked to other tables. So, is
> defining foreign keys for these 10 fields a good idea ? Because from
> what I understand, for every foreign key, there is an index defined.
> So, all these indexes has to be maintained. Is that killing
> performance ? What's the best practise : defining foreign keys or not
> ?

The referencing side of the constraint doesn't need an index, although
it's useful for speeding up deletes or updates to the referenced table
(so, if those operations don't happen or are significantly rare, having
those have to do a sequential scan may be better than the maintenance
cost of the index on the referencing side). The referenced side does need
an index, however that's theoretically the same index that's used to
guarantee the required unique/primary key constraint.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ted Byers 2006-03-29 18:24:03 Re: PostgreSQL's XML support comparison against other RDBMSes
Previous Message Antimon 2006-03-29 18:19:15 Re: PostgreSQL client api