]> granicus.if.org Git - postgresql/commit
Fix AggGetAggref() so it won't lie to aggregate final functions.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 12 Oct 2017 19:20:04 +0000 (15:20 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 12 Oct 2017 19:20:04 +0000 (15:20 -0400)
commitd48bf6a94d295c3779c6af4df118d95a6606192f
treec6e7dbfbff49c7ed20fc7dd24ee9ea8230dca57d
parent5c926e68ea61d0b795ad5438e7223e88d3e2c93f
Fix AggGetAggref() so it won't lie to aggregate final functions.

If we merge the transition calculations for two different aggregates,
it's reasonable to assume that the transition function should not care
which of those Aggref structs it gets from AggGetAggref().  It is not
reasonable to make the same assumption about an aggregate final function,
however.  Commit 804163bc2 broke this, as it will pass whichever Aggref
was first associated with the transition state in both cases.

This doesn't create an observable bug so far as the core system is
concerned, because the only existing uses of AggGetAggref() are in
ordered-set aggregates that happen to not pay attention to anything
but the input properties of the Aggref; and besides that, we disabled
sharing of transition calculations for OSAs yesterday.  Nonetheless,
if some third-party code were using AggGetAggref() in a normal aggregate,
they would be entitled to call this a bug.  Hence, back-patch the fix
to 9.6 where the problem was introduced.

In passing, improve some of the comments about transition state sharing.

Discussion: https://postgr.es/m/CAB4ELO5RZhOamuT9Xsf72ozbenDLLXZKSk07FiSVsuJNZB861A@mail.gmail.com
src/backend/executor/nodeAgg.c
src/include/nodes/execnodes.h