/* Simple Vars always escape being wrapped */
wrap = false;
}
+ else if (newnode && IsA(newnode, PlaceHolderVar) &&
+ ((PlaceHolderVar *) newnode)->phlevelsup == 0)
+ {
+ /* No need to wrap a PlaceHolderVar with another one, either */
+ wrap = false;
+ }
else if (rcon->wrap_non_vars)
{
/* Wrap all non-Vars in a PlaceHolderVar */
{
/*
* If it contains a Var of current level, and does not contain
- * any non-strict constructs, then it's certainly nullable and
- * we don't need to insert a PlaceHolderVar. (Note: in future
- * maybe we should insert PlaceHolderVars anyway, when a tlist
- * item is expensive to evaluate?
+ * any non-strict constructs, then it's certainly nullable so
+ * we don't need to insert a PlaceHolderVar.
+ *
+ * This analysis could be tighter: in particular, a non-strict
+ * construct hidden within a lower-level PlaceHolderVar is not
+ * reason to add another PHV. But for now it doesn't seem
+ * worth the code to be more exact.
+ *
+ * Note: in future maybe we should insert a PlaceHolderVar
+ * anyway, if the tlist item is expensive to evaluate?
*/
if (contain_vars_of_level((Node *) newnode, 0) &&
!contain_nonstrict_functions((Node *) newnode))