aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/createplan.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-03-10 16:23:40 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-03-10 16:23:52 -0500
commitc82c92b111b7b636e80f8a432de10c62011b35b6 (patch)
treecf0accbfe09768c55fbd19b41707f5b2c0d835af /src/backend/optimizer/plan/createplan.c
parentfd31cd265138019dcccc9b5fe53043670898bc9f (diff)
downloadpostgresql-c82c92b111b7b636e80f8a432de10c62011b35b6.tar.gz
postgresql-c82c92b111b7b636e80f8a432de10c62011b35b6.zip
Give pull_var_clause() reject/recurse/return behavior for WindowFuncs too.
All along, this function should have treated WindowFuncs in a manner similar to Aggrefs, ie with an option whether or not to recurse into them. By not considering the case, it was always recursing, which is OK for most callers (although I suspect that the case in prepare_sort_from_pathkeys might represent a bug). But now we need return-without-recursing behavior as well. There are also more than a few callers that should never see a WindowFunc, and now we'll get some error checking on that.
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r--src/backend/optimizer/plan/createplan.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 243e41d0cde..d138728e679 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -5307,7 +5307,8 @@ prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys,
* that we treat Aggrefs as if they were variables; this is
* necessary when attempting to sort the output from an Agg node
* for use in a WindowFunc (since grouping_planner will have
- * treated the Aggrefs as variables, too).
+ * treated the Aggrefs as variables, too). Likewise, if we find a
+ * WindowFunc in a sort expression, treat it as a variable.
*/
Expr *sortexpr = NULL;
@@ -5336,6 +5337,7 @@ prepare_sort_from_pathkeys(Plan *lefttree, List *pathkeys,
sortexpr = em->em_expr;
exprvars = pull_var_clause((Node *) sortexpr,
PVC_INCLUDE_AGGREGATES |
+ PVC_INCLUDE_WINDOWFUNCS |
PVC_INCLUDE_PLACEHOLDERS);
foreach(k, exprvars)
{