pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Noah Misch <noah@leadboat.com>
Cc: Matthijs Bomhoff <matthijs@quarantainenet.nl>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Re: Bug with STABLE function using the wrong snapshot (probably during planning)
Date: Thu, 12 May 2011 18:46:40 -0400
Message-ID: <11903.1305240400@sss.pgh.pa.us> (raw)
In-Reply-To: <20110510093124.GE5617@tornado.gateway.2wire.net>
References: <DF84581C-FFCF-42D7-AB80-50872A677BC6@quarantainenet.nl>
	<20110510093124.GE5617@tornado.gateway.2wire.net>

Noah Misch <noah@leadboat.com> 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



view thread (4+ messages)  latest in thread

Message-ID: <11903.1305240400@sss.pgh.pa.us>
Permalink:  ../11903.1305240400@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11903.1305240400@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, noah@leadboat.com, matthijs@quarantainenet.nl
  Subject: Re: Bug with STABLE function using the wrong snapshot (probably during planning)
  In-Reply-To: <11903.1305240400@sss.pgh.pa.us>
  References: <DF84581C-FFCF-42D7-AB80-50872A677BC6@quarantainenet.nl> <20110510093124.GE5617@tornado.gateway.2wire.net> <11903.1305240400@sss.pgh.pa.us>

* 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