pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan Wieck <janwieck@yahoo.com>
To: Mikheev, Vadim <vmikheev@SECTORBASE.COM>
Cc: 'Rini Dutta' <rinid@rocketmail.com>
Cc: pgsql-sql@hub.org, pgsql-hackers@hub.org, "Jan Wieck \\(E-mail\\)" <janwieck@yahoo.com>
Subject: Re: foreign key introduces unnecessary locking ?
Date: Sun, 22 Oct 2000 07:26:12 -0500 (EST)
Message-ID: <200010221226.HAA00859@jupiter.jw.home> (raw)
In-Reply-To: <8F4C99C66D04D4118F580090272A7A23018D41@SECTORBASE1>

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@Yahoo.com #





view thread (6+ messages)  latest in thread

Message-ID: <200010221226.HAA00859@jupiter.jw.home>
Permalink:  ../200010221226.HAA00859@jupiter.jw.home/
Also on:    postgresql.org/message-id/200010221226.HAA00859@jupiter.jw.home

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: janwieck@yahoo.com, vmikheev@SECTORBASE.COM, rinid@rocketmail.com
  Subject: Re: foreign key introduces unnecessary locking ?
  In-Reply-To: <200010221226.HAA00859@jupiter.jw.home>
  References: <8F4C99C66D04D4118F580090272A7A23018D41@SECTORBASE1> <200010221226.HAA00859@jupiter.jw.home>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox