Re: Freeing transient memory in aggregate functions

2021-12-21 Thread Matt Magoffin
On 21/12/2021, at 10:25 AM, Tom Lane wrote: > Not quite like that. Look into nodeAgg.c, which solves a similar problem > for the transvalues themselves with code like > >/* forget the old value, if any */ >if (!oldIsNull && !pertrans->inputtypeByVal) >pfre

Re: Freeing transient memory in aggregate functions

2021-12-20 Thread Tom Lane
Matt Magoffin writes: > I’m essentially doing a datumCopy() on every non-null input value. If you're doing that in the aggContext, you definitely need to free the prior one(s). > I was wondering if there is a way to free the previously copied datum, since > I don’t really need it anymore? Somet

Freeing transient memory in aggregate functions

2021-12-20 Thread Matt Magoffin
I have a question about trying to keep memory from growing too much in a C aggregate function with pass-by-reference types. I am trying to keep track of a last-seen value in my aggregate state, so I have code roughly doing this: Datum current; MemoryContext aggContext; AggCheckCallContext(fcinfo