Skip site navigation (1) Skip section navigation (2)


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: FOR SHARE vs FOR UPDATE locks
Date: 2006-11-30 22:06:13
Message-ID: (view raw or whole thread)
Lists: pgsql-docspgsql-hackers
I just realized that we have a bit of a problem with upgrading row
locks.  Consider the following sequence:

regression=# begin;
regression=# select * from int4_tbl where f1 = 0 for share;
(1 row)

regression=# savepoint x;
regression=# select * from int4_tbl where f1 = 0 for update;
(1 row)

regression=# rollback to x;

The FOR UPDATE replaces the former shared row lock with an exclusive
lock in the name of the subtransaction.  After the ROLLBACK, the row
appears not to be locked at all (it is ex-locked with XMAX = a failed
transaction), so another backend could come along and modify it.
That shouldn't happen --- we should act as though the outer
transaction's FOR SHARE lock is still held.

Unfortunately, I don't think there is any good way to implement that,
since we surely don't have room in the tuple header to track multiple
locks.  One possibility is to try to assign the ex-lock in the name
of the highest subtransaction holding a row lock, but that seems messy,
and it wouldn't really have the correct semantics anyway --- in the
above example, the outer transaction would be left holding ex-lock
which would be surprising.

I'm tempted to just error out in this scenario rather than allow the
lock upgrade.  Thoughts?

			regards, tom lane


pgsql-docs by date

Next:From: Robert TreatDate: 2006-12-01 00:30:31
Subject: Re: DTrace docs, Open Items and Performance
Previous:From: Tom LaneDate: 2006-11-28 22:54:55
Subject: Re: [HACKERS] pg_dump -t broken for mixed case table names in beta3?

pgsql-hackers by date

Next:From: Andrew DunstanDate: 2006-11-30 22:10:04
Subject: Re: little anoyance with configure
Previous:From: Martijn van OosterhoutDate: 2006-11-30 21:54:28
Subject: Re: little anoyance with configure

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group