From: Tom Lane <tgl@sss.pgh.pa.us>
To: duncan.burke@orionvm.com.au
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6608: SELECT FOR UPDATE not obtaining row exclusive locks in CTEs
Date: Wed, 25 Apr 2012 18:02:41 -0400
Message-ID: <5673.1335391361@sss.pgh.pa.us> (raw)
In-Reply-To: <E1SMBtD-0006lv-FG@wrigleys.postgresql.org>
References: <E1SMBtD-0006lv-FG@wrigleys.postgresql.org>
duncan.burke@orionvm.com.au writes:
> I found that running a SELECT FOR UPDATE query in a CTE does not block
> simultaneous transactions from running the same query.
The reason this test case doesn't do anything:
> CREATE FUNCTION lock_0(int) returns int as $$
> WITH locked as (
> SELECT 1 FROM foo
> WHERE x = $1
> FOR UPDATE)
> SELECT 1
> $$ LANGUAGE SQL;
is that the CTE is unreferenced. While we force INSERT/UPDATE/DELETE
CTEs to be executed even when not referenced, that does not apply to
SELECTs; see
http://www.postgresql.org/docs/9.1/static/queries-with.html
which states "execution of a SELECT is carried only as far as the
primary query demands its output".
If I change the function to say "WITH ... SELECT * FROM locked" then
blocking occurs as expected.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, duncan.burke@orionvm.com.au
Subject: Re: BUG #6608: SELECT FOR UPDATE not obtaining row exclusive locks in CTEs
In-Reply-To: <5673.1335391361@sss.pgh.pa.us>
References: <E1SMBtD-0006lv-FG@wrigleys.postgresql.org> <5673.1335391361@sss.pgh.pa.us>
* 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