Re: foreign key introduces unnecessary locking ?

From: Jan Wieck <janwieck(at)yahoo(dot)com>
To: "Mikheev, Vadim" <vmikheev(at)SECTORBASE(dot)COM>
Cc: "'Rini Dutta'" <rinid(at)rocketmail(dot)com>, pgsql-sql(at)hub(dot)org, pgsql-hackers(at)hub(dot)org, "Jan Wieck \\(E-mail\\)" <janwieck(at)yahoo(dot)com>
Subject: Re: foreign key introduces unnecessary locking ?
Date: 2000-10-22 12:26:12
Message-ID: 200010221226.HAA00859@jupiter.jw.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Mikheev, Vadim wrote:
> Try this for both FK tables:
>
> create table tmp2(idx2 int4, col2 int4, constraint
> tmpcon2 foreign key(col2) references tmp1(idx) INITIALLY DEFERRED);
>
> This will defer constraint checks till transaction commit...
> though constraint triggers should use SnapshotDirty instead of
> SELECT FOR UPDATE anyway.
>
> Did you consider this, Jan?
>
> Vadim

Whenever the checks are done, the transaction inserting a new
reference to the key must ensure that this key cannot get
deleted until it is done and it's newly inserted reference is
visible to others. Otherwise a referential action,
preventing referenced key deletion (or other action) wouldn't
see those and it would be possible to violate the constraint.

I don't see any other way doing it than obtaining a lock.
Using SnapshotDirty would mean, that one transaction could
DELETE a reference, then another transaction removes the
primary key (because using Dirty the DELETE is already
visible), but now the first transaction rolls back. Voila,
constraint violated.

Jan

--

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jan Wieck 2000-10-22 17:41:36 Re: Re: [HACKERS] My new job
Previous Message Bruce Hartzler 2000-10-22 09:25:38 howto: install posgresql on darwin/osxpb

Browse pgsql-sql by date

  From Date Subject
Next Message jan.bajerski 2000-10-23 15:11:06
Previous Message Richard DeVenezia 2000-10-21 14:18:07 Help: Using a regular expression match as a value