Re: Foreign Key Columns And Indices

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
Cc: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Foreign Key Columns And Indices
Date: 2001-02-05 17:29:55
Message-ID: Pine.BSF.4.21.0102050923150.37315-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 5 Feb 2001, Philip Warner wrote:

> PGSQL implements PK/FK & Unique constraints by using indexes (and rules) at
> the moment. There is no guarantee that this will always be the case - in
> fact, one path to rationalizing the constraints system is to implement most
> features as SQL CHECK constraints:
>
> PK: Check( (Select Count(*) from Table Where PKCOLS=PKCOLS) = 1)
> FK: Check( (Select Count(*) from PK_Table Where PKCOLS=FKCOLS) = 1)

There are a couple of problems with this for the fk case. The biggest
is that check constraints with subselects won't currently do the
correct thing (even if it allowed you to specify them). We could
replace the current trigger on insert/update of fk table with a check
constraint assuming we made it possible to defer check constraints,
but all of the stuff on the pk table won't work that way due to
the referential actions and the fact that you need to check after delete
on pk rows (which AFAIK we don't currently do for check constraints).

The spec gives the check version of the foreign key constraint but it
was unfortunate that they also added functionality which then made that
insufficient. :(

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Lamar Owen 2001-02-05 17:32:04 Re: pg_ctl wish list
Previous Message Mathieu Dube 2001-02-05 17:20:45 Re: Re: 1024 limits??