Re: are foreign keys realized as indexes?

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Felix Kater <fkater(at)googlemail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: are foreign keys realized as indexes?
Date: 2007-05-08 12:26:12
Message-ID: 46406C64.8050401@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/05/2007 13:14, Felix Kater wrote:

> There is *no complete* substitute for foreign keys by using *indexes*
> since I'd loose the referencial integrity (whereas for unique contraints
> there *is* a full replacement using indexes)?

Here's my understanding....an index is just that (an index) and no more
- it tells PostgreSQL where to look in a table to find a particular row
or set of rows. A foreign key, on the other hand, ensures that
referential integrity is enforced: it enforces the relationship between
rows in a table which refer to rows in another table, depending on how
the foreign key was specified in the first place (cf. the "ON UPDATE...
ON DELETE... etc. clauses).

When you have a foreign key, you can put an index on the foreign key
column in the "child" table for performance reasons, but this *isn't*
the same as the foreign key.

I don't know about the equivalence of unique constraints and indices -
others on the list can answer that.

Ray.

---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
---------------------------------------------------------------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Felix Kater 2007-05-08 12:34:29 Re: are foreign keys realized as indexes?
Previous Message Anoo Pillai 2007-05-08 12:21:12 Time of previous REINDEX execution..