|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.239 2008/08/05 16:03:10 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.240 2008/08/07 01:11:50 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -68,10 +68,6 @@ static double preprocess_limit(PlannerInfo *root,
|
68 | 68 | double tuple_fraction,
|
69 | 69 | int64 *offset_est, int64 *count_est);
|
70 | 70 | static void preprocess_groupclause(PlannerInfo *root);
|
71 |
| -static Oid *extract_grouping_ops(List *groupClause); |
72 |
| -static AttrNumber *extract_grouping_cols(List *groupClause, List *tlist); |
73 |
| -static bool grouping_is_sortable(List *groupClause); |
74 |
| -static bool grouping_is_hashable(List *groupClause); |
75 | 71 | static bool choose_hashed_grouping(PlannerInfo *root,
|
76 | 72 | double tuple_fraction, double limit_tuples,
|
77 | 73 | Path *cheapest_path, Path *sorted_path,
|
@@ -784,10 +780,9 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
|
784 | 780 |
|
785 | 781 | /*
|
786 | 782 | * If there's a top-level ORDER BY, assume we have to fetch all the
|
787 |
| - * tuples. This might seem too simplistic given all the hackery below |
788 |
| - * to possibly avoid the sort ... but a nonzero tuple_fraction is only |
789 |
| - * of use to plan_set_operations() when the setop is UNION ALL, and |
790 |
| - * the result of UNION ALL is always unsorted. |
| 783 | + * tuples. This might be too simplistic given all the hackery below |
| 784 | + * to possibly avoid the sort; but the odds of accurate estimates |
| 785 | + * here are pretty low anyway. |
791 | 786 | */
|
792 | 787 | if (parse->sortClause)
|
793 | 788 | tuple_fraction = 0.0;
|
@@ -818,7 +813,8 @@ grouping_planner(PlannerInfo *root, double tuple_fraction)
|
818 | 813 | */
|
819 | 814 | Assert(parse->commandType == CMD_SELECT);
|
820 | 815 |
|
821 |
| - tlist = postprocess_setop_tlist(result_plan->targetlist, tlist); |
| 816 | + tlist = postprocess_setop_tlist(copyObject(result_plan->targetlist), |
| 817 | + tlist); |
822 | 818 |
|
823 | 819 | /*
|
824 | 820 | * Can't handle FOR UPDATE/SHARE here (parser should have checked
|
@@ -1714,100 +1710,6 @@ preprocess_groupclause(PlannerInfo *root)
|
1714 | 1710 | parse->groupClause = new_groupclause;
|
1715 | 1711 | }
|
1716 | 1712 |
|
1717 |
| -/* |
1718 |
| - * extract_grouping_ops - make an array of the equality operator OIDs |
1719 |
| - * for a SortGroupClause list |
1720 |
| - */ |
1721 |
| -static Oid * |
1722 |
| -extract_grouping_ops(List *groupClause) |
1723 |
| -{ |
1724 |
| - int numCols = list_length(groupClause); |
1725 |
| - int colno = 0; |
1726 |
| - Oid *groupOperators; |
1727 |
| - ListCell *glitem; |
1728 |
| - |
1729 |
| - groupOperators = (Oid *) palloc(sizeof(Oid) * numCols); |
1730 |
| - |
1731 |
| - foreach(glitem, groupClause) |
1732 |
| - { |
1733 |
| - SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); |
1734 |
| - |
1735 |
| - groupOperators[colno] = groupcl->eqop; |
1736 |
| - Assert(OidIsValid(groupOperators[colno])); |
1737 |
| - colno++; |
1738 |
| - } |
1739 |
| - |
1740 |
| - return groupOperators; |
1741 |
| -} |
1742 |
| - |
1743 |
| -/* |
1744 |
| - * extract_grouping_cols - make an array of the grouping column resnos |
1745 |
| - * for a SortGroupClause list |
1746 |
| - */ |
1747 |
| -static AttrNumber * |
1748 |
| -extract_grouping_cols(List *groupClause, List *tlist) |
1749 |
| -{ |
1750 |
| - AttrNumber *grpColIdx; |
1751 |
| - int numCols = list_length(groupClause); |
1752 |
| - int colno = 0; |
1753 |
| - ListCell *glitem; |
1754 |
| - |
1755 |
| - grpColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols); |
1756 |
| - |
1757 |
| - foreach(glitem, groupClause) |
1758 |
| - { |
1759 |
| - SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); |
1760 |
| - TargetEntry *tle = get_sortgroupclause_tle(groupcl, tlist); |
1761 |
| - |
1762 |
| - grpColIdx[colno++] = tle->resno; |
1763 |
| - } |
1764 |
| - |
1765 |
| - return grpColIdx; |
1766 |
| -} |
1767 |
| - |
1768 |
| -/* |
1769 |
| - * grouping_is_sortable - is it possible to implement grouping list by sorting? |
1770 |
| - * |
1771 |
| - * This is easy since the parser will have included a sortop if one exists. |
1772 |
| - */ |
1773 |
| -static bool |
1774 |
| -grouping_is_sortable(List *groupClause) |
1775 |
| -{ |
1776 |
| - ListCell *glitem; |
1777 |
| - |
1778 |
| - foreach(glitem, groupClause) |
1779 |
| - { |
1780 |
| - SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); |
1781 |
| - |
1782 |
| - if (!OidIsValid(groupcl->sortop)) |
1783 |
| - return false; |
1784 |
| - } |
1785 |
| - return true; |
1786 |
| -} |
1787 |
| - |
1788 |
| -/* |
1789 |
| - * grouping_is_hashable - is it possible to implement grouping list by hashing? |
1790 |
| - * |
1791 |
| - * We assume hashing is OK if the equality operators are marked oprcanhash. |
1792 |
| - * (If there isn't actually a supporting hash function, the executor will |
1793 |
| - * complain at runtime; but this is a misdeclaration of the operator, not |
1794 |
| - * a system bug.) |
1795 |
| - */ |
1796 |
| -static bool |
1797 |
| -grouping_is_hashable(List *groupClause) |
1798 |
| -{ |
1799 |
| - ListCell *glitem; |
1800 |
| - |
1801 |
| - foreach(glitem, groupClause) |
1802 |
| - { |
1803 |
| - SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); |
1804 |
| - |
1805 |
| - if (!op_hashjoinable(groupcl->eqop)) |
1806 |
| - return false; |
1807 |
| - } |
1808 |
| - return true; |
1809 |
| -} |
1810 |
| - |
1811 | 1713 | /*
|
1812 | 1714 | * choose_hashed_grouping - should we use hashed grouping?
|
1813 | 1715 | *
|
|
0 commit comments