diff options
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r-- | src/backend/optimizer/plan/createplan.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index d668128ccb1..65a2e38fc33 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -937,10 +937,12 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path) if (newitems || best_path->umethod == UNIQUE_PATH_SORT) { /* - * If the top plan node can't do projections, we need to add a Result - * node to help it along. + * If the top plan node can't do projections and its existing target + * list isn't already what we need, we need to add a Result node to + * help it along. */ - if (!is_projection_capable_plan(subplan)) + if (!is_projection_capable_plan(subplan) && + !tlist_same_exprs(newtlist, subplan->targetlist)) subplan = (Plan *) make_result(root, newtlist, NULL, subplan); else subplan->targetlist = newtlist; |