be allowed to receive ungrouped variables of the current query level.
Curious that no one reported this bug before...
if (node == NULL)
return false;
+ /*
+ * If we find an aggregate function, do not recurse into its
+ * arguments. Subplans invoked within aggregate calls are allowed
+ * to receive ungrouped variables.
+ */
+ if (IsA(node, Aggref))
+ return false;
+
/*
* We can ignore Vars other than in subplan args lists, since the
* parser already checked 'em.