pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: duncan.burke@orionvm.com.au
To: pgsql-bugs@postgresql.org
Subject: BUG #6608: SELECT FOR UPDATE not obtaining row exclusive locks in CTEs
Date: Mon, 23 Apr 2012 05:32:43 +0000
Message-ID: <E1SMBtD-0006lv-FG@wrigleys.postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      6608
Logged by:          Duncan Burke
Email address:      duncan.burke@orionvm.com.au
PostgreSQL version: 9.1.3
Operating system:   gentoo
Description:        

I found that running a SELECT FOR UPDATE query in a CTE does not block
simultaneous transactions from running the same query. i.e it appears to not
be obtaining an exclusive row lock as expected.

CREATE TABLE foo (
    x int PRIMARY KEY,
    y int
);

INSERT INTO foo VALUES (0,0);

CREATE FUNCTION lock_0(int) returns int as $$
    WITH locked as (
        SELECT 1 FROM foo
        WHERE x = $1
        FOR UPDATE)
    SELECT 1
$$ LANGUAGE SQL;

CREATE FUNCTION lock_1(int) returns int as $$
    WITH locked as (
        UPDATE FOO
        SET y = y
        WHERE x = $1)
    SELECT 1
$$ LANGUAGE SQL;


--run in two simultaneous transactions, lock_0 does not block
BEGIN;
SELECT lock_0(0);
COMMIT;

--run in two simultaneous transactions, lock_1 blocks
BEGIN;
SELECT lock_1(0);
COMMIT;




view thread (2+ messages)  latest in thread

Message-ID: <E1SMBtD-0006lv-FG@wrigleys.postgresql.org>
Permalink:  ../E1SMBtD-0006lv-FG@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1SMBtD-0006lv-FG@wrigleys.postgresql.org

 · 

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 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: duncan.burke@orionvm.com.au
  Subject: Re: BUG #6608: SELECT FOR UPDATE not obtaining row exclusive locks in CTEs
  In-Reply-To: <E1SMBtD-0006lv-FG@wrigleys.postgresql.org>
  References: <E1SMBtD-0006lv-FG@wrigleys.postgresql.org>

* 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