]> granicus.if.org Git - postgresql/commit
Fix the handling of sub-SELECTs appearing in the arguments of an outer-level
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 25 Apr 2009 16:45:03 +0000 (16:45 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 25 Apr 2009 16:45:03 +0000 (16:45 +0000)
commit8f61f0b8439aa0f0e6eda40206f26316f10f052d
treeacd9abd904cedcc7a3b0176668b1baae43532fea
parent0fca584ac8f3cf59ae82ea897a33b9d6b75d324c
Fix the handling of sub-SELECTs appearing in the arguments of an outer-level
aggregate function.  By definition, such a sub-SELECT cannot reference any
variables of query levels between itself and the aggregate's semantic level
(else the aggregate would've been assigned to that lower level instead).
So the correct, most efficient implementation is to treat the sub-SELECT as
being a sub-select of that outer query level, not the level the aggregate
syntactically appears in.  Not doing so also confuses the heck out of our
parameter-passing logic, as illustrated in bug report from Daniel Grace.

Fortunately, we were already copying the whole Aggref expression up to the
outer query level, so all that's needed is to delay SS_process_sublinks
processing of the sub-SELECT until control returns to the outer level.

This has been broken since we introduced spec-compliant treatment of
outer aggregates in 7.4; so patch all the way back.
src/backend/optimizer/plan/subselect.c
src/test/regress/expected/aggregates.out
src/test/regress/sql/aggregates.sql