diff --git a/src/backend/optimizer/plan/planagg.c b/src/backend/optimizer/plan/planagg.c
index 805aae7..9a103b4 100644
--- a/src/backend/optimizer/plan/planagg.c
+++ b/src/backend/optimizer/plan/planagg.c
@@ -203,21 +203,22 @@ preprocess_minmax_aggregates(PlannerInfo *root, List *tlist)
 	 * other needed data, and add it to the UPPERREL_GROUP_AGG upperrel, where
 	 * it will compete against the standard aggregate implementation.  (It
 	 * will likely always win, but we need not assume that here.)
 	 *
 	 * Note: grouping_planner won't have created this upperrel yet, but it's
 	 * fine for us to create it first.  We will not have inserted the correct
 	 * consider_parallel value in it, but MinMaxAggPath paths are currently
 	 * never parallel-safe anyway, so that doesn't matter.  Likewise, it
 	 * doesn't matter that we haven't filled FDW-related fields in the rel.
 	 */
-	grouped_rel = fetch_upper_rel(root, UPPERREL_GROUP_AGG, NULL);
+	grouped_rel = fetch_upper_rel(root, UPPERREL_GROUP_AGG,
+								  bms_make_singleton(rtr->rtindex));
 	add_path(grouped_rel, (Path *)
 			 create_minmaxagg_path(root, grouped_rel,
 								   create_pathtarget(root, tlist),
 								   aggs_list,
 								   (List *) parse->havingQual));
 }
 
 /*
  * find_minmax_aggs_walker
  *		Recursively scan the Aggref nodes in an expression tree, and check
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index f657ffc..9b072df 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3332,21 +3332,21 @@ create_grouping_paths(PlannerInfo *root,
 	Size		hashaggtablesize;
 	double		dNumGroups;
 	double		dNumPartialGroups = 0;
 	bool		can_hash;
 	bool		can_sort;
 	bool		try_parallel_aggregation;
 
 	ListCell   *lc;
 
 	/* For now, do all work in the (GROUP_AGG, NULL) upperrel */
-	grouped_rel = fetch_upper_rel(root, UPPERREL_GROUP_AGG, NULL);
+	grouped_rel = fetch_upper_rel(root, UPPERREL_GROUP_AGG, input_rel->relids);
 
 	/*
 	 * If the input relation is not parallel-safe, then the grouped relation
 	 * can't be parallel-safe, either.  Otherwise, it's parallel-safe if the
 	 * target list and HAVING quals are parallel-safe.
 	 */
 	if (input_rel->consider_parallel &&
 		is_parallel_safe(root, (Node *) target->exprs) &&
 		is_parallel_safe(root, (Node *) parse->havingQual))
 		grouped_rel->consider_parallel = true;
