I think that the PVC_RECURSE_WINDOWFUNCS flag shouldn't be used in make_partial_grouping_target().
First, this function uses the grouping_target (see grouping_planner()) as the input, and that should only contain the input expressions of window functions as opposed to the window functions themselves. (make_window_input_target() is responsible for pulling the input expressions from the window functions.) Second, if a window function appeared in the result of make_partial_grouping_target() for any reason, the Agg node would fail to evaluate it. Am I wrong? -- Antonin Houska Web: https://www.cybertec-postgresql.com
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index e664eb18c0..c5b9e45098 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -5349,7 +5349,6 @@ make_partial_grouping_target(PlannerInfo *root, */ non_group_exprs = pull_var_clause((Node *) non_group_cols, PVC_INCLUDE_AGGREGATES | - PVC_RECURSE_WINDOWFUNCS | PVC_INCLUDE_PLACEHOLDERS); add_new_columns_to_pathtarget(partial_target, non_group_exprs);