postgresql/src
Tom Lane 1679e9fedd Fix window functions that sort by expressions involving aggregates.
In commit c1d9579dd8, I changed things so
that the output of the Agg node that feeds the window functions would not
list any ungrouped Vars directly.  Formerly, for example, the Agg tlist
might have included both "x" and "sum(x)", which is not really valid if
"x" isn't a grouping column.  If we then had a window function ordering on
something like "sum(x) + 1", prepare_sort_from_pathkeys would find no exact
match for this in the Agg tlist, and would conclude that it must recompute
the expression.  But it would break the expression down to just the Var
"x", which it would find in the tlist, and then rebuild the ORDER BY
expression using a reference to the subplan's "x" output.  Now, after the
above-referenced changes, "x" isn't in the Agg tlist if it's not a grouping
column, so that prepare_sort_from_pathkeys fails with "could not find
pathkey item to sort", as reported by Bricklen Anderson.

The fix is to not break down Aggrefs into their component parts, but just
treat them as irreducible expressions to be sought in the subplan tlist.
This is definitely OK for the use with respect to window functions in
grouping_planner, since it just built the tlist being used on the same
basis.  AFAICT it is safe for other uses too; most of the other call sites
couldn't encounter Aggrefs anyway.
2011-09-26 23:49:12 -04:00
..
backend Fix window functions that sort by expressions involving aggregates. 2011-09-26 23:49:12 -04:00
bin Un-break compression of plain-text output format in pg_dump. 2011-09-25 13:59:35 -04:00
include Stamp 9.1.1. 2011-09-22 17:57:57 -04:00
interfaces Stamp 9.1.1. 2011-09-22 17:57:57 -04:00
makefiles Fix pgxs.mk to always add --dbname=$(CONTRIB_TESTDB) to REGRESS_OPTS. 2011-08-24 15:17:03 -04:00
pl Translation updates for 9.1.0 2011-09-08 23:10:40 +03:00
port Stamp 9.1.1. 2011-09-22 17:57:57 -04:00
template
test Fix window functions that sort by expressions involving aggregates. 2011-09-26 23:49:12 -04:00
timezone Fix our mapping of Windows timezones for Central America. 2011-09-23 22:12:36 -04:00
tools Fix MinGW build, broken by my previous patch to add a setlocale() wrapper 2011-09-01 14:04:19 +03:00
tutorial
.gitignore
bcc32.mak
DEVELOPERS
Makefile
Makefile.global.in Make distprep and *clean build targets recurse into all subdirectories. 2011-07-03 13:55:27 -04:00
Makefile.shlib Use single quotes in preference to double quotes for protecting pathnames. 2011-06-15 21:45:50 -04:00
nls-global.mk
win32.mak