Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-05 Thread Alvaro Herrera
On 2019-Jun-03, Andres Freund wrote: > On 2019-06-03 11:45:51 -0400, Elvis Pranskevichus wrote: > > It is understandably late in the 12 cycle, so maybe prohibit NOT > > MATERIALIZED with DML altogheter and revisit this in 13? > > I could see us adding an error, or just continuing to silently ign

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread David Fetter
On Mon, Jun 03, 2019 at 07:33:35PM -0400, Tom Lane wrote: > David Fetter writes: > > It might be worth documenting the fact that NOT MATERIALIZED doesn't > > affect DML CTEs, just as it doesn't affect statements with volatile > > functions and recursive CTEs. > > We already do: > > However,

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Tom Lane
David Fetter writes: > It might be worth documenting the fact that NOT MATERIALIZED doesn't > affect DML CTEs, just as it doesn't affect statements with volatile > functions and recursive CTEs. We already do: However, if a WITH query is non-recursive and side-effect-free (that is, it is

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread David Fetter
On Mon, Jun 03, 2019 at 11:45:51AM -0400, Elvis Pranskevichus wrote: > Currently, WITH a AS NOT MATERIALIZED (INSERT ...) would silently > disregard the "NOT MATERIALIZED" instruction and execute the data- > modifying CTE to completion (as per the long-standing DML CTE rule). > > This seems like

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Elvis Pranskevichus
On Monday, June 3, 2019 1:03:44 P.M. EDT Tom Lane wrote: > 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 materiali

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Tom Lane
Elvis Pranskevichus 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 >>> evalua

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Elvis Pranskevichus
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

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Tom Lane
Elvis Pranskevichus writes: > On Monday, June 3, 2019 11:50:15 A.M. EDT Andres Freund wrote: >>> This seems like an omission to me. Ideally, the presence of an >>> explicit "NOT MATERIALIZED" clause on a data-modifying CTE should >>> disable the "run to completion" logic. >> I don't see us ever

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Elvis Pranskevichus
On Monday, June 3, 2019 11:50:15 A.M. EDT Andres Freund wrote: > > This seems like an omission to me. Ideally, the presence of an > > explicit "NOT MATERIALIZED" clause on a data-modifying CTE should > > disable the "run to completion" logic. > > I don't see us ever doing that. The result of mino

Re: WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Andres Freund
Hi, On 2019-06-03 11:45:51 -0400, Elvis Pranskevichus wrote: > Currently, WITH a AS NOT MATERIALIZED (INSERT ...) would silently > disregard the "NOT MATERIALIZED" instruction and execute the data- > modifying CTE to completion (as per the long-standing DML CTE rule). > > This seems like an omis

WITH NOT MATERIALIZED and DML CTEs

2019-06-03 Thread Elvis Pranskevichus
Currently, WITH a AS NOT MATERIALIZED (INSERT ...) would silently disregard the "NOT MATERIALIZED" instruction and execute the data- modifying CTE to completion (as per the long-standing DML CTE rule). This seems like an omission to me. Ideally, the presence of an explicit "NOT MATERIALIZED" cl