I went ahead and pushed the stuff about QTW_EXAMINE_RTES_BEFORE/_AFTER,because that seems like an independent change with other possible uses.

Attached is an updated version of the rest of the patch, with mostlycosmetic changes. I've not touched the documentation, but I think thisis otherwise committable if we are satisfied with the semantics.

However ... after thinking about it more, I'm not really satisfiedwith that. In particular I don't like the fact that by default thiswill inline regardless of the number of references to the CTE. I doubtthat inlining when there are multiple references is so likely to be awin as to justify it being the default, especially given that it fliesin the face of what our documentation has said for as long as we'vehad CTEs.

Therefore, I'm reversing my previous opinion that we should not havean explicit NOT MATERIALIZED option. I think we should add that, andthe behavior ought to be:

* No option given: inline if there's exactly one reference.

* With MATERIALIZED: never inline.

* With NOT MATERIALIZED: inline regardless of the number of references.

(Obviously, we should not inline if there's RECURSIVE or the CTEpotentially has side-effects, regardless of the user option;I don't think those cases are up for debate.)

I haven't done anything about that here, but the changes would be prettyminor.