From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Fetter <david@fetter.org>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5754: CTE optimization fails to account for side effects
Date: Mon, 15 Nov 2010 18:55:47 -0500
Message-ID: <10323.1289865347@sss.pgh.pa.us> (raw)
In-Reply-To: <201011152211.oAFMBOmm031718@wwwmaster.postgresql.org>
References: <201011152211.oAFMBOmm031718@wwwmaster.postgresql.org>
"David Fetter" <david@fetter.org> writes:
> CREATE SEQUENCE my_seq;
> WITH t AS (SELECT nextval('my_seq')) VALUES(1);
> SELECT currval('my_seq');
> ERROR: currval of sequence "my_seq" is not yet defined in this session
> What's happened is that the optimization didn't account for the idea that a
> SELECT might have a side effect, and if we're going with the "CTEs execute
> exactly once and (equivalent to) fully," this is a bug.
The reason it's not a bug is that we have not adopted that position.
There is a proposal to make it so for wCTEs, but that doesn't mean
we should change the existing, documented and useful behavior of regular
CTEs.
(If you're wondering where it's documented, I cite section 7.8's
statement that only as much of a CTE query is evaluated as is read by
the parent query. The limiting case of that is no reference -> no rows
read.)
regards, tom lane
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, david@fetter.org
Subject: Re: BUG #5754: CTE optimization fails to account for side effects
In-Reply-To: <10323.1289865347@sss.pgh.pa.us>
References: <201011152211.oAFMBOmm031718@wwwmaster.postgresql.org> <10323.1289865347@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