Improve cost estimation for aggregates and window functions.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Apr 2011 20:55:20 +0000 (16:55 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 24 Apr 2011 20:55:20 +0000 (16:55 -0400)
commite6a30a8c3c81a7a2949f852379d34a19dfc26a0d
treed6abe75c107e16a658e565f08e77983ce22c9495
parentf6322b31918c5c57eeea80c26a088af44d573095
Improve cost estimation for aggregates and window functions.

The previous coding failed to account properly for the costs of evaluating
the input expressions of aggregates and window functions, as seen in a
recent gripe from Claudio Freire.  (I said at the time that it wasn't
counting these costs at all; but on closer inspection, it was effectively
charging these costs once per output tuple.  That is completely wrong for
aggregates, and not exactly right for window functions either.)

There was also a hard-wired assumption that aggregates and window functions
had procost 1.0, which is now fixed to respect the actual cataloged costs.

The costing of WindowAgg is still pretty bogus, since it doesn't try to
estimate the effects of spilling data to disk, but that seems like a
separate issue.
src/backend/optimizer/path/costsize.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/planagg.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/prep/prepunion.c
src/backend/optimizer/util/clauses.c
src/backend/optimizer/util/pathnode.c
src/include/nodes/relation.h
src/include/optimizer/clauses.h
src/include/optimizer/cost.h
src/include/optimizer/planmain.h