Re: Wrong FOR UPDATE lock type - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Wrong FOR UPDATE lock type
Date
Msg-id 7039.975966712@sss.pgh.pa.us
Whole thread Raw
In response to Re: Wrong FOR UPDATE lock type  (Jan Wieck <janwieck@Yahoo.com>)
List pgsql-hackers
Jan Wieck <janwieck@Yahoo.com> writes:
>     Tom,
>     IIRC  the  "Deadlock risk" debug message is from you. I think
>     it must get a little smarter. IMHO an application that want's
>     to  UPDATE  something  in  a  transaction but must SELECT the
>     row(s) first to do it's own calculation on them,  should  use
>     SELECT FOR UPDATE. Is that debug output really appropriate in
>     this case (it raises from  RowShareLock  to  RowExclusiveLock
>     because  of  the  UPDATE  of the previous FOR UPDATE selected
>     row)?

Well, there is a theoretical chance of deadlock --- not against other
transactions doing the same thing, since RowShareLock and
RowExclusiveLock don't conflict, but you could construct deadlock
scenarios involving other transactions that grab ShareLock or
ShareRowExclusiveLock.  So I don't think it's appropriate for the
"deadlock risk" check to ignore RowShareLock->RowExclusiveLock
upgrades.

But I'm not sure the check should be enabled in production releases
anyway.  I just put it in as a quick and dirty debug check.  Perhaps
it should be under an #ifdef that's not enabled by default.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Thomas Good
Date:
Subject: Debian build failing...
Next
From: Adam Haberlach
Date:
Subject: Re: Using Threads?