Re: "deadlock detected" / cascading locks

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: Matt Mello <alien(at)spaceship(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: "deadlock detected" / cascading locks
Date: 2003-05-20 01:01:43
Message-ID: 3EC97E77.40503@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Stephan Szabo wrote:
> [...]

Yupp

>>And, do these locks cascade? If I choose to do an update on table A,
>>and it has a foreign key to table B, which has a foreign key to table C,
>>does the update-induced lock on A cause a lock on B /and/ C?
>
>
> Not for checks since those don't change the table in question. It's
> possible for locks to cascade through referential action effects (although
> that effect is partially minimized by the bug fix mentioned for
> update unless the referencing column is itself the one being referenced)

Normally referential actions like ON DELETE CASCADE will cascade top
town, parent->child->grandchild. If an update to table A cascades
through a referential integrity constraint into an update to table B,
there is no possible deadlock through this action by itself. The primary
key colum(s) in A being updated must have a UNIQUE constraint (as per
SQL standard). Having a lock for that column(s) in A means (logically in
this context) having a lock on all referencing rows in B. So noone else
can attempt to update these rows "through this constraints referential
action".

The other way around there can be multiple path's upward from many
tables to common RI ancestors. But the checks done do not cascade up
since they only lock for update. With my patch they don't even do that
"if the referencing columns did not change.

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

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-05-20 04:51:46 Re: Performance on temp table inserts
Previous Message Dean Gibson (DB Administrator) 2003-05-20 00:28:05 Re: Testing castability of text to numeric