From 82480e28f5744582dba78320824e3569ed76e74a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 20 Jun 2009 18:45:28 +0000 Subject: Fix things so that array_agg_finalfn does not modify or free its input ArrayBuildState, per trouble report from Merlin Moncure. By adopting this fix, we are essentially deciding that aggregate final-functions should not modify their inputs ever. Adjust documentation and comments to match that conclusion. --- doc/src/sgml/xaggr.sgml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/xaggr.sgml b/doc/src/sgml/xaggr.sgml index b223888f9ed..1175b3640d7 100644 --- a/doc/src/sgml/xaggr.sgml +++ b/doc/src/sgml/xaggr.sgml @@ -1,4 +1,4 @@ - + User-Defined Aggregates @@ -175,10 +175,14 @@ SELECT attrelid::regclass, array_accum(atttypid::regtype) (IsA(fcinfo->context, AggState) || IsA(fcinfo->context, WindowAggState))) - One reason for checking this is that when it is true, the first input + One reason for checking this is that when it is true for a transition + function, the first input must be a temporary transition value and can therefore safely be modified in-place rather than allocating a new copy. (This is the only - case where it is safe for a function to modify a pass-by-reference input.) + case where it is safe for a function to modify a pass-by-reference input. + In particular, aggregate final functions should not modify their inputs in + any case, because in some cases they will be re-executed on the same + final transition value.) See int8inc() for an example. -- cgit v1.2.3