Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id BCEE7B5D90E for ; Thu, 12 May 2011 19:46:48 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 41391-10 for ; Thu, 12 May 2011 22:46:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 72982B5DBE3 for ; Thu, 12 May 2011 19:46:41 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p4CMkeV9011905; Thu, 12 May 2011 18:46:40 -0400 (EDT) To: Noah Misch cc: Matthijs Bomhoff , pgsql-bugs@postgresql.org Subject: Re: Re: Bug with STABLE function using the wrong snapshot (probably during planning) In-reply-to: <20110510093124.GE5617@tornado.gateway.2wire.net> References: <20110510093124.GE5617@tornado.gateway.2wire.net> Comments: In-reply-to Noah Misch message dated "Tue, 10 May 2011 05:31:24 -0400" Date: Thu, 12 May 2011 18:46:40 -0400 Message-ID: <11903.1305240400@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/117 X-Sequence-Number: 30256 Noah Misch writes: >> Some initial debugging by RhodiumToad on #postgresql led to the following observation: The error occurs only when the "SELECT ... WHERE i = a_bar();" is being planned, not when it is being executed, with the snapshot being used to plan the query apparently being too old to see the result of the preceding insert. > The simplest fix I can see is to have _SPI_prepare_plan() push/pop a new > snapshot when analyze_requires_snapshot() returns true on the raw parse tree. > That strategy can break down in the other direction if the caller is STABLE; > consider this example: Yes. I'm of the opinion that we should not change this. In general, marking functions STABLE that have major side effects (such as throwing errors) is not a good idea, and putting such things into WHERE clauses is a worse one. We explicitly do not guarantee anything about timing or order of evaluation in WHERE clauses, because to do so would cripple the planner's ability to optimize them. So I think this is a "don't do that" case rather than "we should try to make planning happen with the same snapshot that will be used at execution" case. regards, tom lane