|
10 | 10 | *
|
11 | 11 | *
|
12 | 12 | * IDENTIFICATION
|
13 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.239 2008/04/13 20:51:20 tgl Exp $ |
| 13 | + * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.240 2008/04/17 21:22:14 tgl Exp $ |
14 | 14 | *
|
15 | 15 | *-------------------------------------------------------------------------
|
16 | 16 | */
|
@@ -115,6 +115,7 @@ static MergeJoin *make_mergejoin(List *tlist,
|
115 | 115 | static Sort *make_sort(PlannerInfo *root, Plan *lefttree, int numCols,
|
116 | 116 | AttrNumber *sortColIdx, Oid *sortOperators, bool *nullsFirst,
|
117 | 117 | double limit_tuples);
|
| 118 | +static Material *make_material(Plan *lefttree); |
118 | 119 |
|
119 | 120 |
|
120 | 121 | /*
|
@@ -616,12 +617,14 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path)
|
616 | 617 | * add any such expressions to the subplan's tlist.
|
617 | 618 | *
|
618 | 619 | * The subplan may have a "physical" tlist if it is a simple scan plan.
|
619 |
| - * This should be left as-is if we don't need to add any expressions; |
| 620 | + * If we're going to sort, this should be reduced to the regular tlist, |
| 621 | + * so that we don't sort more data than we need to. For hashing, the |
| 622 | + * tlist should be left as-is if we don't need to add any expressions; |
620 | 623 | * but if we do have to add expressions, then a projection step will be
|
621 |
| - * needed at runtime anyway, and so we may as well remove unneeded items. |
| 624 | + * needed at runtime anyway, so we may as well remove unneeded items. |
622 | 625 | * Therefore newtlist starts from build_relation_tlist() not just a
|
623 | 626 | * copy of the subplan's tlist; and we don't install it into the subplan
|
624 |
| - * unless stuff has to be added. |
| 627 | + * unless we are sorting or stuff has to be added. |
625 | 628 | *
|
626 | 629 | * To find the correct list of values to unique-ify, we look in the
|
627 | 630 | * information saved for IN expressions. If this code is ever used in
|
@@ -669,7 +672,7 @@ create_unique_plan(PlannerInfo *root, UniquePath *best_path)
|
669 | 672 | }
|
670 | 673 | }
|
671 | 674 |
|
672 |
| - if (newitems) |
| 675 | + if (newitems || best_path->umethod == UNIQUE_PATH_SORT) |
673 | 676 | {
|
674 | 677 | /*
|
675 | 678 | * If the top plan node can't do projections, we need to add a Result
|
@@ -2850,7 +2853,7 @@ make_sort_from_groupcols(PlannerInfo *root,
|
2850 | 2853 | sortColIdx, sortOperators, nullsFirst, -1.0);
|
2851 | 2854 | }
|
2852 | 2855 |
|
2853 |
| -Material * |
| 2856 | +static Material * |
2854 | 2857 | make_material(Plan *lefttree)
|
2855 | 2858 | {
|
2856 | 2859 | Material *node = makeNode(Material);
|
|
0 commit comments