Re: WITH NOT MATERIALIZED and DML CTEs

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Elvis Pranskevichus <elprans(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Andres Freund <andres(at)anarazel(dot)de>
Subject: Re: WITH NOT MATERIALIZED and DML CTEs
Date: 2019-06-03 17:03:44
Message-ID: 10679.1559581424@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Elvis Pranskevichus <elprans(at)gmail(dot)com> writes:
> On Monday, June 3, 2019 12:09:46 P.M. EDT Tom Lane wrote:
>>> I understand why the rule exists in the first place, but I think
>>> that an explicit opt-in signals the assumption of responsibility
>>> and opens the possibility of using this in a well-defined
>>> evaluation context, such as CASE WHEN.

>> TBH, if you think it's well-defined, you're wrong.

> The documentation seems to strongly suggest otherwise:

> "When it is essential to force evaluation order, a CASE construct (see
> Section 9.17) can be used. ... CASE construct used in this fashion will
> defeat optimization attempts"

> Are there cases where this is not true outside of the documented
> exceptions (i.e. immutable early-eval and aggregates)?

CASE is a scalar-expression construct. It's got little to do with
the timing of scan/join operations such as row fetches. We offer
users essentially no control over when those happen ... other than
the guarantees about CTE materialization, which are exactly what
you say you want to give up.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-06-03 17:26:54 Re: Fix inconsistencies for v12
Previous Message Elvis Pranskevichus 2019-06-03 16:29:41 Re: WITH NOT MATERIALIZED and DML CTEs