pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: lars@greiz-reinsdorf.de
To: pgsql-bugs@postgresql.org
Subject: BUG #7798: Query in a rule does not see committed transaction
Date: Mon, 07 Jan 2013 15:35:24 +0000
Message-ID: <E1TsEjU-00064V-MT@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      7798
Logged by:          Lars Kanis
Email address:      lars@greiz-reinsdorf.de
PostgreSQL version: 9.1.7
Operating system:   Linux - Ubuntu 12.04
Description:        

Everything in isolation level "read committed".

Database setup:

CREATE TABLE cards ( id serial primary key, auswname varchar );
CREATE TABLE cards_status_cache ( id INT PRIMARY KEY, response_ok VARCHAR
);
CREATE TABLE card_actions ( id serial PRIMARY KEY, card_id integer NOT NULL
DEFAULT 0, uid VARCHAR );
INSERT INTO cards ( id, auswname ) VALUES (1, 'test1');
INSERT INTO card_actions (id, card_id) VALUES (5, 1);
CREATE OR REPLACE RULE expire_cards_status_cache AS ON UPDATE TO
card_actions
 DO (
  SELECT id FROM cards WHERE (id = OLD.card_id) OR (id = NEW.card_id) FOR
UPDATE OF cards;
  DELETE FROM cards_status_cache WHERE (id = OLD.card_id) OR (id =
NEW.card_id);
 );


Now run within session one:

BEGIN;
  SELECT id FROM cards WHERE id=1 FOR UPDATE;
  INSERT INTO cards_status_cache (id, response_ok) VALUES (1, 'resp1');
  SELECT pg_sleep(10);
COMMIT;


While above pg_sleep() is running, start in a second session:

UPDATE card_actions SET uid = 'abcdef01' WHERE card_actions.id = 5;
SELECT * FROM cards_status_cache;

The second session blocks until the first has finished, because the rule on
card_actions
acquires a row lock that is already held by the first session. When session
one
has committed, the DELETE statement should find the inserted row (in
isolation level
"read committed"), but does not. So the result of session two should be
empty, but
instead one row is returned.

If the UPDATE statement is executed twice within a transaction, the second
run sees
the row to delete, but not the first one, that waits for the lock.


Regards,
Lars





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



Message-ID: <E1TsEjU-00064V-MT@wrigleys.postgresql.org>
Permalink:  ../E1TsEjU-00064V-MT@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/E1TsEjU-00064V-MT@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: lars@greiz-reinsdorf.de
  Subject: Re: BUG #7798: Query in a rule does not see committed transaction
  In-Reply-To: <E1TsEjU-00064V-MT@wrigleys.postgresql.org>
  References: <E1TsEjU-00064V-MT@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