Re: Foreign keys question (performance) - Mailing list pgsql-general

From Phoenix Kiula
Subject Re: Foreign keys question (performance)
Date
Msg-id CAFWfU=tNz63sZQf=LJJWjzqrDJx6rx=8XkOuJSj8rVZ6FRcRYg@mail.gmail.com
Whole thread Raw
In response to Re: Foreign keys question (performance)  (Alban Hertroys <haramrae@gmail.com>)
Responses Re: Foreign keys question (performance)
List pgsql-general
On Sun, Dec 4, 2011 at 7:14 PM, Alban Hertroys <haramrae@gmail.com> wrote:
> On 4 Dec 2011, at 11:19, Phoenix Kiula wrote:
....

>
> INSERTs in the parent table don't need to check for any reference from the child table, since they're new; there
can'tbe a reference. UPDATEs and DELETEs do though, whether you let them CASCADE or not. If you don't, then the
databaseraises a foreign key constraint violation. If you do, then it needs to modify the relevant rows in the child
table.
>
> Likewise, INSERTs and UPDATEs in the child table need to verify that - if their reference key changed - they're still
referencinga valid row. 



Thanks Albert. Very useful.

I had ON DELETE...ALSO DELETE rules earlier and in some cases they let
some keys go by in associated tables. Hope foreign key constraint is
more reliable!

PK

pgsql-general by date:

Previous
From: Phoenix Kiula
Date:
Subject: Weird behavior: deleted row still in index?
Next
From: Alban Hertroys
Date:
Subject: Re: Weird behavior: deleted row still in index?