BUG #6608: SELECT FOR UPDATE not obtaining row exclusive locks in CTEs

Поиск
Список
Период
Сортировка
От duncan.burke@orionvm.com.au
Тема BUG #6608: SELECT FOR UPDATE not obtaining row exclusive locks in CTEs
Дата
Msg-id E1SMBtD-0006lv-FG@wrigleys.postgresql.org
обсуждение исходный текст
Ответы Re: BUG #6608: SELECT FOR UPDATE not obtaining row exclusive locks in CTEs  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
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:=20=20=20=20=20=20=20=20

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 =3D $1
        FOR UPDATE)
    SELECT 1
$$ LANGUAGE SQL;

CREATE FUNCTION lock_1(int) returns int as $$
    WITH locked as (
        UPDATE FOO
        SET y =3D y
        WHERE x =3D $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;

В списке pgsql-bugs по дате отправления:

Предыдущее
От: suvisor.root@gmail.com
Дата:
Сообщение: BUG #6607: Strange select behavior
Следующее
От: Gavin Flower
Дата:
Сообщение: Re: BUG #6605: wrong type cast from timestamp to timestamptz