pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Markus Bertheau <twanger@bluetwanger.de>
Cc: Bruno Wolff III <bruno@wolff.to>
Cc: pgsql-sql@postgresql.org
Subject: Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo
Date: Tue, 17 Aug 2004 08:09:19 -0700 (PDT)
Message-ID: <20040817075821.V61699@megazone.bigpanda.com> (raw)
In-Reply-To: <1092752492.2627.23.camel@dicaprio.akademie1.de>
References: <1092740863.2627.17.camel@dicaprio.akademie1.de>
	<20040817141229.GA15770@wolff.to>
	<1092752492.2627.23.camel@dicaprio.akademie1.de>

On Tue, 17 Aug 2004, Markus Bertheau wrote:

> В Втр, 17.08.2004, в 16:12, Bruno Wolff III пишет:
> > > SELECT MAX(position) FROM (SELECT position FROM classes WHERE name =
> > > 'foo' FOR UPDATE OF classes) AS foo
> > >
> > > It's clear which rows should be locked here, I think.
> >
> > Even if it was allowed, it probably wouldn't be good enough because it won't
> > protect against newly inserted records.
>
> Can you detail an example where this wouldn't be good enough?

Another transaction can come along and insert a row with name='foo' into
classes with a higher position value after you've done the above but
before you commit.

T1: begin;
T2: begin;
T1: select max(position) from (select position from classes where
name='foo' for update of classes) as foo;
 -- say this gets 5
T2: insert into classes (name, position) values ('foo', 10);
 -- This wouldn't be blocked by the for update lock.
T2: commit;
 -- now if you were to do the T1 select above, you'd get a different
 -- answer in read committed.

If we had predicate locking, I think you could probably manage these cases
in serializable mode, but for now I'm not sure anything less than a table
lock would do.



view thread (8+ messages)  latest in thread

Message-ID: <20040817075821.V61699@megazone.bigpanda.com>
Permalink:  ../20040817075821.V61699@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20040817075821.V61699@megazone.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, twanger@bluetwanger.de, bruno@wolff.to
  Subject: Re: SELECT MAX(c) FROM (SELECT ... FOR UPDATE) AS foo
  In-Reply-To: <20040817075821.V61699@megazone.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox