From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | David Fetter <david(at)fetter(dot)org> |
Cc: | Elvis Pranskevichus <elprans(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: WITH NOT MATERIALIZED and DML CTEs |
Date: | 2019-06-03 23:33:35 |
Message-ID: | 26493.1559604815@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
David Fetter <david(at)fetter(dot)org> 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 a SELECT containing no volatile functions) then it can be
folded into the parent query, allowing joint optimization of the two
query levels. By default, this happens if the parent query references
the WITH query just once, but not if it references the WITH query more
than once. You can override that decision by specifying MATERIALIZED
to force separate calculation of the WITH query, or by specifying NOT
MATERIALIZED to force it to be merged into the parent query. The
latter choice risks duplicate computation of the WITH query, but it
can still give a net savings if each usage of the WITH query needs
only a small part of the WITH query's full output.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Ashwin Agrawal | 2019-06-03 23:53:48 | Re: Confusing error message for REINDEX TABLE CONCURRENTLY |
Previous Message | David Fetter | 2019-06-03 23:14:28 | Re: WITH NOT MATERIALIZED and DML CTEs |