Re: foreign key introduces unnecessary locking ? - Mailing list pgsql-hackers

From Stephan Szabo
Subject Re: foreign key introduces unnecessary locking ?
Date
Msg-id Pine.BSF.4.10.10010091622270.21346-100000@megazone23.bigpanda.com
Whole thread Raw
In response to foreign key introduces unnecessary locking ?  (Rini Dutta <rinid@rocketmail.com>)
List pgsql-hackers
On Mon, 2 Oct 2000, Rini Dutta wrote:

> 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 ?

Each is attempting to grab row locks on tmp1 to prevent 
the rows from going away while we're testing the 
references. The second transaction is waiting for the row 
lock to go away so that it can do its row lock.
I'm not sure why its failing in JDBC though.




pgsql-hackers by date:

Previous
From: "Mikheev, Vadim"
Date:
Subject: RE: foreign key introduces unnecessary locking ?
Next
From: Vince Vielhaber
Date:
Subject: Re: Announcing PgSQL - a Python DB-API 2.0 compliant interface to PostgreSQL