From 3bfe957761ace9290072690a6298fc0eb996d857 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 27 Feb 2018 13:18:59 -0500 Subject: [PATCH] Fix logic error in add_paths_to_partial_grouping_rel. Commit 3bf05e096b9f8375e640c5d7996aa57efd7f240c sometimes uses the cheapest_partial_path variable in this function to mean the cheapest one from the input rel and at other times the cheapest one from the partially grouped rel, but it never resets it, so we can end up with bad plans, leading to "ERROR: Aggref found in non-Agg plan node". Jeevan Chalke, per a report from Andreas Joseph Krogh and a separate off-list report from Rajkumar Raghuwanshi Discussion: http://postgr.es/m/CAM2+6=X9kxQoL2ZqZ00E6asBt9z+rfyWbOmhXJ0+8fPAyMZ9Jg@mail.gmail.com --- src/backend/optimizer/plan/planner.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index e8f6cc559b..819067536f 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -6339,6 +6339,9 @@ add_paths_to_partial_grouping_rel(PlannerInfo *root, */ generate_gather_paths(root, partially_grouped_rel, true); + /* Get cheapest partial path from partially_grouped_rel */ + cheapest_partial_path = linitial(partially_grouped_rel->partial_pathlist); + /* * generate_gather_paths won't consider sorting the cheapest path to match * the group keys and then applying a Gather Merge node to the result; -- 2.40.0