>>>>> "Tom" == Tom Lane <tgl@sss.pgh.pa.us> writes:
Tom> We can't inline wCTEs (those containing insert/update/delete)
Tom> without risk of semantics change.
Clearly.
Tom> I'd also not favor changing the semantics for CTEs that are read
Tom> more than once by the parent query.
This one's more debatable. There will still be cases where a CTE
referenced multiple times will be better inlined.
(It's obviously trivial to make the posted code do it that way, just by
checking cterefcount.)
Tom> However, a singly-referenced SELECT CTE could reasonably be
Tom> treated as equivalent to a sub-select-in-FROM,
In the PoC code I also excluded SELECT FOR UPDATE from inlining.
(There's already a difference between how SELECT FOR UPDATE works for
CTEs compared to subqueries and views, the comments mention it)
There might also be some merit in checking for volatility?
--
Andrew (irc:RhodiumToad)