diff options
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index b5827d39808..62b2354f004 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -5300,8 +5300,11 @@ create_ordered_paths(PlannerInfo *root, limit_tuples); } - /* Add projection step if needed */ - if (sorted_path->pathtarget != target) + /* + * If the pathtarget of the result path has different expressions from + * the target to be applied, a projection step is needed. + */ + if (!equal(sorted_path->pathtarget->exprs, target->exprs)) sorted_path = apply_projection_to_path(root, ordered_rel, sorted_path, target); @@ -5378,8 +5381,11 @@ create_ordered_paths(PlannerInfo *root, root->sort_pathkeys, NULL, &total_groups); - /* Add projection step if needed */ - if (sorted_path->pathtarget != target) + /* + * If the pathtarget of the result path has different expressions + * from the target to be applied, a projection step is needed. + */ + if (!equal(sorted_path->pathtarget->exprs, target->exprs)) sorted_path = apply_projection_to_path(root, ordered_rel, sorted_path, target); |