Re: Referential Integrity and SHARE locks - Mailing list pgsql-hackers

From Florian G. Pflug
Subject Re: Referential Integrity and SHARE locks
Date
Msg-id 45C328BC.5090404@phlo.org
Whole thread Raw
In response to Re: Referential Integrity and SHARE locks  (Csaba Nagy <nagy@ecircle-ag.com>)
List pgsql-hackers
Csaba Nagy wrote:
> The reason of the occasional orphan rows is not completely clear to me,
> but it must be some kind of race condition while
> inserting/deleting/?updating concurrently the parent/child tables.

I guess the following sequence would generate a orphaned row.
A: executes "insert into table_child parent_id=1"
B: executes "delete from table_parent where id=1"
A: RI trigger checks for matching row in table_parent
B: The row with id=1 is marked as deleted in table_parent
A: The new row with parent_id=1 is inserted into table_child
B: The delete is commited
A: The insert is comitted.

Any ordering that marks the row as deleted between the execution
of the ri-trigger and the insertion of the new row would lead
to the same result..

greetings, Florian Pflug


pgsql-hackers by date:

Previous
From: Csaba Nagy
Date:
Subject: Re: Referential Integrity and SHARE locks
Next
From: Gavin Sherry
Date:
Subject: Re: Bitmap index thoughts