Skip to content

Commit bce352f

Browse files
committed
Remove some bogus logic from create_gather_merge_plan.
This logic was adapated from create_merge_append_plan, but the two cases aren't really analogous, because create_merge_append_plan is not projection-capable and must therefore have a tlist identical to that of the underlying paths. Overwriting the tlist of Gather Merge with whatever the underlying plan happens to produce is no good at all. Patch by me, reviewed by Rushabh Lathia, who also reported the issue and made an initial attempt at a fix. Discussion: http://postgr.es/m/CA+Tgmob_-oHEOBfT9S25bjqokdqv8e8xEmh9zOY+3MPr_LmuhA@mail.gmail.com
1 parent 0c87cd0 commit bce352f

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

src/backend/optimizer/plan/createplan.c

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,17 +1469,12 @@ create_gather_merge_plan(PlannerInfo *root, GatherMergePath *best_path)
14691469
GatherMerge *gm_plan;
14701470
Plan *subplan;
14711471
List *pathkeys = best_path->path.pathkeys;
1472-
int numsortkeys;
1473-
AttrNumber *sortColIdx;
1474-
Oid *sortOperators;
1475-
Oid *collations;
1476-
bool *nullsFirst;
14771472
List *tlist = build_path_tlist(root, &best_path->path);
14781473

14791474
/* As with Gather, it's best to project away columns in the workers. */
14801475
subplan = create_plan_recurse(root, best_path->subpath, CP_EXACT_TLIST);
14811476

1482-
/* See create_merge_append_plan for why there's no make_xxx function */
1477+
/* Create a shell for a GatherMerge plan. */
14831478
gm_plan = makeNode(GatherMerge);
14841479
gm_plan->plan.targetlist = tlist;
14851480
gm_plan->num_workers = best_path->num_workers;
@@ -1488,46 +1483,25 @@ create_gather_merge_plan(PlannerInfo *root, GatherMergePath *best_path)
14881483
/* Gather Merge is pointless with no pathkeys; use Gather instead. */
14891484
Assert(pathkeys != NIL);
14901485

1491-
/* Compute sort column info, and adjust GatherMerge tlist as needed */
1492-
(void) prepare_sort_from_pathkeys(&gm_plan->plan, pathkeys,
1493-
best_path->path.parent->relids,
1494-
NULL,
1495-
true,
1496-
&gm_plan->numCols,
1497-
&gm_plan->sortColIdx,
1498-
&gm_plan->sortOperators,
1499-
&gm_plan->collations,
1500-
&gm_plan->nullsFirst);
1501-
1502-
15031486
/* Compute sort column info, and adjust subplan's tlist as needed */
15041487
subplan = prepare_sort_from_pathkeys(subplan, pathkeys,
15051488
best_path->subpath->parent->relids,
15061489
gm_plan->sortColIdx,
15071490
false,
1508-
&numsortkeys,
1509-
&sortColIdx,
1510-
&sortOperators,
1511-
&collations,
1512-
&nullsFirst);
1491+
&gm_plan->numCols,
1492+
&gm_plan->sortColIdx,
1493+
&gm_plan->sortOperators,
1494+
&gm_plan->collations,
1495+
&gm_plan->nullsFirst);
15131496

1514-
/* As for MergeAppend, check that we got the same sort key information. */
1515-
Assert(numsortkeys == gm_plan->numCols);
1516-
if (memcmp(sortColIdx, gm_plan->sortColIdx,
1517-
numsortkeys * sizeof(AttrNumber)) != 0)
1518-
elog(ERROR, "GatherMerge child's targetlist doesn't match GatherMerge");
1519-
Assert(memcmp(sortOperators, gm_plan->sortOperators,
1520-
numsortkeys * sizeof(Oid)) == 0);
1521-
Assert(memcmp(collations, gm_plan->collations,
1522-
numsortkeys * sizeof(Oid)) == 0);
1523-
Assert(memcmp(nullsFirst, gm_plan->nullsFirst,
1524-
numsortkeys * sizeof(bool)) == 0);
15251497

15261498
/* Now, insert a Sort node if subplan isn't sufficiently ordered */
15271499
if (!pathkeys_contained_in(pathkeys, best_path->subpath->pathkeys))
1528-
subplan = (Plan *) make_sort(subplan, numsortkeys,
1529-
sortColIdx, sortOperators,
1530-
collations, nullsFirst);
1500+
subplan = (Plan *) make_sort(subplan, gm_plan->numCols,
1501+
gm_plan->sortColIdx,
1502+
gm_plan->sortOperators,
1503+
gm_plan->collations,
1504+
gm_plan->nullsFirst);
15311505

15321506
/* Now insert the subplan under GatherMerge. */
15331507
gm_plan->plan.lefttree = subplan;

0 commit comments

Comments
 (0)