Nathaniel Hazelton <nathaniel(at)sturdyai(dot)com> writes:
> The CTE in that location was emulating a view in which we have a CTE -
> which responds the same way. Does this mean CTEs can never be used in
> views that could be flattened without affecting performance?
You've got a view with an unused CTE? Why?
But at any rate, yes, the presence of a CTE is an optimization
fence: we can't flatten the subquery containing it without losing
the query level at which the CTE should be evaluated. Perhaps there
are special cases where that could be relaxed, but nobody's tried
very hard.
regards, tom lane