pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hubert depesz lubaczewski <depesz@depesz.com>
To: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Rows go missing when selecting "for update" after savepoint "play"
Date: Thu, 6 Oct 2016 20:05:33 +0200
Message-ID: <20161006180533.5wq6fcqbdeam3tib@depesz.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Used postgresql: 9.5.4 (from pgdg apt archive)
system: ubuntu trusty

repeatable case:

CREATE TABLE depesz (id serial PRIMARY KEY, x TEXT);
BEGIN;
    INSERT INTO depesz (id, x) VALUES (1,'x');
    SELECT * FROM depesz WHERE id = 1 for UPDATE;
    UPDATE depesz SET x = 'y' WHERE id = 1;
    savepoint i_hate_activerecord;
    SELECT * FROM depesz WHERE id = 1 for UPDATE;
    UPDATE depesz SET x = 'aa' WHERE id = 1;
    rollback to SAVEPOINT i_hate_activerecord;
    SELECT * FROM depesz WHERE id = 1;
    SELECT * FROM depesz WHERE id = 1 for UPDATE; -- here is the problem
    SELECT * FROM depesz WHERE id = 1;
rollback;
DROP TABLE depesz;

on my test system running it looks like:

CREATE TABLE depesz (id serial PRIMARY KEY, x TEXT);
CREATE TABLE
BEGIN;
BEGIN
INSERT INTO depesz (id, x) VALUES (1,'x');
INSERT 0 1
SELECT * FROM depesz WHERE id = 1 for UPDATE;
 id | x 
----+---
  1 | x
(1 row)

UPDATE depesz SET x = 'y' WHERE id = 1;
UPDATE 1
savepoint i_hate_activerecord;
SAVEPOINT
SELECT * FROM depesz WHERE id = 1 for UPDATE;
 id | x 
----+---
  1 | y
(1 row)

UPDATE depesz SET x = 'aa' WHERE id = 1;
UPDATE 1
rollback to SAVEPOINT i_hate_activerecord;
ROLLBACK
SELECT * FROM depesz WHERE id = 1;
 id | x 
----+---
  1 | y
(1 row)

SELECT * FROM depesz WHERE id = 1 for UPDATE;
 id | x 
----+---
(0 rows)

SELECT * FROM depesz WHERE id = 1;
 id | x 
----+---
  1 | y
(1 row)

rollback;
ROLLBACK
DROP TABLE depesz;
DROP TABLE


I think that the marked select for update should return 1 row, because - well, why wouldn't it?

I checked, and the problem is not there in 10.devel.

Best regards,

depesz

-- 
The best thing about modern society is how easy it is to avoid contact with it.
                                                             http://depesz.com/


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (4+ messages)  latest in thread

Message-ID: <20161006180533.5wq6fcqbdeam3tib@depesz.com>
Permalink:  ../20161006180533.5wq6fcqbdeam3tib@depesz.com/
Also on:    postgresql.org/message-id/20161006180533.5wq6fcqbdeam3tib@depesz.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 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: depesz@depesz.com
  Subject: Re: Rows go missing when selecting "for update" after savepoint "play"
  In-Reply-To: <20161006180533.5wq6fcqbdeam3tib@depesz.com>
  References: <20161006180533.5wq6fcqbdeam3tib@depesz.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