diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index d002e6d567..64f0ee55ec 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -1469,17 +1469,12 @@ create_gather_merge_plan(PlannerInfo *root, GatherMergePath *best_path)
 	GatherMerge *gm_plan;
 	Plan	   *subplan;
 	List	   *pathkeys = best_path->path.pathkeys;
-	int			numsortkeys;
-	AttrNumber *sortColIdx;
-	Oid		   *sortOperators;
-	Oid		   *collations;
-	bool	   *nullsFirst;
 	List	   *tlist = build_path_tlist(root, &best_path->path);
 
 	/* As with Gather, it's best to project away columns in the workers. */
 	subplan = create_plan_recurse(root, best_path->subpath, CP_EXACT_TLIST);
 
-	/* See create_merge_append_plan for why there's no make_xxx function */
+	/* Create a shell for a GatherMerge plan. */
 	gm_plan = makeNode(GatherMerge);
 	gm_plan->plan.targetlist = tlist;
 	gm_plan->num_workers = best_path->num_workers;
@@ -1488,46 +1483,25 @@ create_gather_merge_plan(PlannerInfo *root, GatherMergePath *best_path)
 	/* Gather Merge is pointless with no pathkeys; use Gather instead. */
 	Assert(pathkeys != NIL);
 
-	/* Compute sort column info, and adjust GatherMerge tlist as needed */
-	(void) prepare_sort_from_pathkeys(&gm_plan->plan, pathkeys,
-									  best_path->path.parent->relids,
-									  NULL,
-									  true,
-									  &gm_plan->numCols,
-									  &gm_plan->sortColIdx,
-									  &gm_plan->sortOperators,
-									  &gm_plan->collations,
-									  &gm_plan->nullsFirst);
-
-
 	/* Compute sort column info, and adjust subplan's tlist as needed */
 	subplan = prepare_sort_from_pathkeys(subplan, pathkeys,
 										 best_path->subpath->parent->relids,
 										 gm_plan->sortColIdx,
 										 false,
-										 &numsortkeys,
-										 &sortColIdx,
-										 &sortOperators,
-										 &collations,
-										 &nullsFirst);
+										 &gm_plan->numCols,
+										 &gm_plan->sortColIdx,
+										 &gm_plan->sortOperators,
+										 &gm_plan->collations,
+										 &gm_plan->nullsFirst);
 
-	/* As for MergeAppend, check that we got the same sort key information. */
-	Assert(numsortkeys == gm_plan->numCols);
-	if (memcmp(sortColIdx, gm_plan->sortColIdx,
-			   numsortkeys * sizeof(AttrNumber)) != 0)
-		elog(ERROR, "GatherMerge child's targetlist doesn't match GatherMerge");
-	Assert(memcmp(sortOperators, gm_plan->sortOperators,
-				  numsortkeys * sizeof(Oid)) == 0);
-	Assert(memcmp(collations, gm_plan->collations,
-				  numsortkeys * sizeof(Oid)) == 0);
-	Assert(memcmp(nullsFirst, gm_plan->nullsFirst,
-				  numsortkeys * sizeof(bool)) == 0);
 
 	/* Now, insert a Sort node if subplan isn't sufficiently ordered */
 	if (!pathkeys_contained_in(pathkeys, best_path->subpath->pathkeys))
-		subplan = (Plan *) make_sort(subplan, numsortkeys,
-									 sortColIdx, sortOperators,
-									 collations, nullsFirst);
+		subplan = (Plan *) make_sort(subplan, gm_plan->numCols,
+									 gm_plan->sortColIdx,
+									 gm_plan->sortOperators,
+									 gm_plan->collations,
+									 gm_plan->nullsFirst);
 
 	/* Now insert the subplan under GatherMerge. */
 	gm_plan->plan.lefttree = subplan;