BUG #5754: CTE optimization fails to account for side effects

From: "David Fetter" <david(at)fetter(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #5754: CTE optimization fails to account for side effects
Date: 2010-11-15 22:11:24
Message-ID: 201011152211.oAFMBOmm031718@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 5754
Logged by: David Fetter
Email address: david(at)fetter(dot)org
PostgreSQL version: 8.4+
Operating system: All
Description: CTE optimization fails to account for side effects
Details:

Here's how to reproduce:

BEGIN;
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.

CTEs should not optimize away (parts of) SELECTs that have side effects.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2010-11-15 23:55:47 Re: BUG #5754: CTE optimization fails to account for side effects
Previous Message Heikki Linnakangas 2010-11-15 21:28:31 Bug in concurrency control in temporary GiST indexes