Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id A56343B5C20 for ; Tue, 27 Dec 2011 22:45:04 -0400 (AST) Received: from m13-64.163.com ([220.181.13.64]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RfjVi-0004MP-PT for pgsql-bugs@postgresql.org; Wed, 28 Dec 2011 02:45:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Received:Date:From:To:Cc:Message-ID:In-Reply-To: References:Subject:MIME-Version:Content-Type; bh=9xYoe5B2E0E215U f5XD6sq8JsXVI4IJ8vfV6QvpGexM=; b=kCutDRkAYn8+nxlxYqbWYmFZ/6A8GJ3 fJK1fPHFL587FbNDnMxsjS6/GhdaX6I+TQf1XV55GR/TQt8wJX+ZcWqz3UJrpGvm BDI9H7auishJokL6jjPVSiwG2UA9R5SYu3wkL+3x6rBMlMcuK2IoqecRyYeeYUOj GXrXMsZzjqPw= Received: from wcting163 ( [210.56.193.18] ) by ajax-webmail-wmsvr64 (Coremail) ; Wed, 28 Dec 2011 10:44:39 +0800 (CST) Date: Wed, 28 Dec 2011 10:44:39 +0800 (CST) From: wcting163 To: "Tom Lane" Cc: pgsql-bugs@postgresql.org Message-ID: <765ac25d.11190.134828e204f.Coremail.wcting163@163.com> In-Reply-To: <11717.1325008040@sss.pgh.pa.us> References: <11717.1325008040@sss.pgh.pa.us> Subject: Re: BUG #6360: with hold cursor, cause function executed twice and wrong results MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_347182_1173607114.1325040279631" X-Originating-IP: [210.56.193.18] X-Priority: 1 X-Mailer: Coremail Webmail Server Version SP_ntes V3.5 build 111202(16086.4213.4207) Copyright (c) 2002-2011 www.mailtech.cn 163com X-CM-CTRLDATA: 9xqDgmZvb3Rlcl9odG09MjMwMzo4MQ== X-CM-TRANSID: QMGowECp+ECYgvpOvuULAA--.3798W X-CM-SenderInfo: pzfwx0jjrwjqqrwthudrp/1tbiowckukzQSen8TgABs1 X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== X-Pg-Spam-Score: -3.2 (---) X-Archive-Number: 201112/233 X-Sequence-Number: 32044 ------=_Part_347182_1173607114.1325040279631 Content-Type: text/plain; charset=GBK Content-Transfer-Encoding: 7bit At 2011-12-28 01:47:20,"Tom Lane" tgl@sss.pgh.pa.us> wrote: Yup. I don't particularly see this as a bug. If you were to manually >rewind and rescan the cursor (ie, MOVE BACKWARD ALL and re-fetch), >the function would be executed multiple times too. If you don't want >that to happen, the best way would be to commit the transaction >immediately, not fetch some rows and then commit. > > regards, tom lane Why *with hold cursor* acts as *MOVE BACKWARD ALL & FETCH*? Is this right or necessary? maybe they are not comparable, i doubt this analogy. MOVE BACKWARD ALL & FETCH will cause cursor re-fetch? Maybe pepole have different opinions for MOVE BACKWARD ALL & FETCH: 1. fetch from the old result-sets, not rescan(re-execute); 2. re-fetch and generate the new result-sets, cause plan re-execute again; Now, pg acts as the second; *Move* is not SQL standard, and does not clearly documented in pg document, If we create *DestTuplestore* when first fetch, not in commit transaction, then: 1. we always fetch results from *DestTuplestore*; 2. if *DestTuplestore* is empty, we execute-plan and fill the results into *DestTuplestore*; 3. when rewind, just rewind *DestTuplestore*, not executor; then we can implement the first action? So, there are two questions here: 1. the Standard action of *MOVE BACKWARD ALL & FETCH*; 2. *with hold cursor* acts as *MOVE BACKWARD ALL & FETCH*, is this right(necessary)? ------=_Part_347182_1173607114.1325040279631 Content-Type: text/html; charset=GBK Content-Transfer-Encoding: 7bit
At 2011-12-28 01:47:20,"Tom Lane" tgl@sss.pgh.pa.us> wrote:
Yup.  I don't particularly see this as a bug.  If you were to manually
>rewind and rescan the cursor (ie, MOVE BACKWARD ALL and re-fetch),
>the function would be executed multiple times too.  If you don't want
>that to happen, the best way would be to commit the transaction
>immediately, not fetch some rows and then commit.
>
> regards, tom lane
Why *with hold cursor* acts as *MOVE BACKWARD ALL & FETCH*?
Is this right or necessary? maybe they are not comparable, i doubt this analogy.
 
MOVE BACKWARD ALL & FETCH will cause cursor re-fetch?
 Maybe pepole have different opinions for MOVE BACKWARD ALL & FETCH:
 1. fetch from the old result-sets, not rescan(re-execute);
 2. re-fetch and generate the new result-sets, cause plan re-execute again;
 
Now, pg acts as the second; 
*Move* is not SQL standard, and does not clearly documented in pg document,
 
If we create *DestTuplestore* when first fetch, not in commit transaction, then:
1. we always fetch results from *DestTuplestore*;
2. if *DestTuplestore* is empty, we execute-plan and fill the results into *DestTuplestore*;
3. when rewind, just rewind *DestTuplestore*, not executor;
 
then we can implement the first action?
 
So, there are two questions here:
1. the Standard action of *MOVE BACKWARD ALL & FETCH*;
2. *with hold cursor* acts as *MOVE BACKWARD ALL & FETCH*, is this right(necessary)?
 
 


------=_Part_347182_1173607114.1325040279631--