foreign key introduces unnecessary locking ?

From: Rini Dutta <rinid(at)rocketmail(dot)com>
To: pgsql-sql(at)hub(dot)org
Cc: pgsql-hackers(at)hub(dot)org
Subject: foreign key introduces unnecessary locking ?
Date: 2000-10-02 15:39:51
Message-ID: 20001002153951.12654.qmail@web2904.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

Hi,

When two tables (table2 and table3) have foreign keys
referring to a common table(table1), I am unable to
have 2 concurrent transactions - one performing insert
on table1 and the other on table2, when the records
being inserted have the same foreign key.

If I use JDBC, one of the transactions aborts.
If I open 2 psql sessions and try the same, one just
waits and does not show the prompt until the other
transaction has been committed or aborted.

For example,
create table tmp1(idx int4, data int4);
create table tmp2(idx2 int4, col2 int4, constraint
tmpcon2 foreign key(col2) references tmp1(idx));
create table tmp3(idx3 int4, col3 int4, constraint
tmpcon3 foreign key(col3) references tmp1(idx));
insert into tmp1 values(1, 1);

Transaction 1 :
begin work;
insert into tmp2 values(2, 1);

Transaction2 :
begin work;
insert into tmp3 values(3,1);

Since such transactions are common for me, for the
time-being I have dropped the foreign key constraint.
Any ideas ?

Rini

__________________________________________________
Do You Yahoo!?
Yahoo! Photos - 35mm Quality Prints, Now Get 15 Free!
http://photos.yahoo.com/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2000-10-02 15:49:58 Re: www.postgresql.org
Previous Message Trond Eivind =?iso-8859-1?q?Glomsr=F8d?= 2000-10-02 15:35:18 Re: failed assertion error on PG-7.0.2

Browse pgsql-sql by date

  From Date Subject
Next Message Carolyn Lu Wong 2000-10-03 00:50:42 trigger question
Previous Message Josh Berkus 2000-10-02 15:39:42 Concerns about the OID