Re: Handling memory contexts in aggregate function invoking other built-in aggregate functions
От | Tom Lane |
---|---|
Тема | Re: Handling memory contexts in aggregate function invoking other built-in aggregate functions |
Дата | |
Msg-id | 2643578.1638634565@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Handling memory contexts in aggregate function invoking other built-in aggregate functions (Matt Magoffin <postgresql.org@msqr.us>) |
Ответы |
Re: Handling memory contexts in aggregate function invoking other built-in aggregate functions
Re: Handling memory contexts in aggregate function invoking other built-in aggregate functions |
Список | pgsql-general |
Matt Magoffin <postgresql.org@msqr.us> writes: > So far, I have been working on average support via the vec_to_mean() aggregate, and my aggregate's [2] transition functionsets up a FunctionCallInfo for the numeric_avg_accum() [3] function and then loops over the input array elements,calling numeric_avg_accum() and saving its result state object in my aggregate’s state. Before looping, I switchthe memory context to the aggregate’s context, i.e. there is stuff like > MemoryContext aggContext; > AggCheckCallContext(fcinfo, &aggContext); > old = MemoryContextSwitchTo(aggContext); > for (i = 0; i < arrayLength; i++) { > // invoke numeric_avg_accum() for each array element, store result in my state > } > MemoryContextSwitchTo(old); Calling numeric_avg_accum in the agg_context is unnecessary, and possibly counterproductive (it might leak memory in that context, since like all other aggregates it assumes it's called in a short-lived context). That doesn't seem to explain your crash though. Are you testing in an --enable-cassert build? If not, do that; it might make the cause of the crashes more apparent, thanks to CLOBBER_FREED_MEMORY and other debug support. regards, tom lane
В списке pgsql-general по дате отправления: