pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: wcting163 <wcting163@163.com>
To: pgsql-bugs@postgresql.org
Subject: with hold cursor, cause function execute twice and wrong result
Date: Wed, 28 Dec 2011 10:09:20 +0800 (CST)
Message-ID: <684bfc49.10560.134826dcb72.Coremail.wcting163@163.com> (raw)

postgres=# select version();
                                                          version
------------------------------------------------------------------------------------------------------------------------
---
 PostgreSQL 9.0alpha5 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Asianux 3.0 4.1.2-44), 64-b
it
 
create table test_execute(id int,name varchar(40));
insert into test_execute values(1,'jack');
create or replace function p_test_execute() returns void
as
$$
begin
        raise notice 'hello world';
        update test_execute set id=id*2;
end;
$$ LANGUAGE plpgsql;
 
begin;
declare JDBC_CURS_1 cursor with hold for select p_test_execute() from test_execute;
fetch 50 from JDBC_CURS_1;
NOTICE:  hello world
end;
NOTICE:  hello world
COMMIT
select * from test_execute;
 id | name
----+------
  4 | jack
 
I expect id = 2, but it is **4** instead,
 
The reason is that the function p_test_execute is executed twice, when *fetch*, it is first executed, and when transaction commit, because the cursor is a *holdable* cursor, it is executed again.
 
I read the code, for holdable cursor, when commit, following call will execute:
 CommitHoldablePortals-->PersistHoldablePortal-->ExecutorRewind.
 
Is *ExecutorRewind* necessary, is it the root of this bug?
Does *ExecutorRewind* cause plan re-execute?

view thread (2+ messages)  latest in thread

Message-ID: <684bfc49.10560.134826dcb72.Coremail.wcting163@163.com>
Permalink:  ../684bfc49.10560.134826dcb72.Coremail.wcting163@163.com/
Also on:    postgresql.org/message-id/684bfc49.10560.134826dcb72.Coremail.wcting163@163.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: wcting163@163.com
  Subject: Re: with hold cursor, cause function execute twice and wrong result
  In-Reply-To: <684bfc49.10560.134826dcb72.Coremail.wcting163@163.com>
  References: <684bfc49.10560.134826dcb72.Coremail.wcting163@163.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