From db3ac67d8f0e00949dcca3691ab00d1d2f8e1e72 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Thu, 15 Feb 2001 21:47:08 +0000
Subject: [PATCH] Update comments about memory management.

---
 src/backend/executor/nodeAgg.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 7c2ef8646b3..bfb2646b6a6 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -29,12 +29,24 @@
  *	  of course).  A non-strict finalfunc can make its own choice of
  *	  what to return for a NULL ending transvalue.
  *
+ *	  When the transvalue datatype is pass-by-reference, we have to be
+ *	  careful to ensure that the values survive across tuple cycles yet
+ *	  are not allowed to accumulate until end of query.  We do this by
+ *	  "ping-ponging" between two memory contexts; successive calls to the
+ *	  transfunc are executed in alternate contexts, passing the previous
+ *	  transvalue that is in the other context.  At the beginning of each
+ *	  tuple cycle we can reset the current output context to avoid memory
+ *	  usage growth.  Note: we must use MemoryContextContains() to check
+ *	  whether the transfunc has perhaps handed us back one of its input
+ *	  values rather than a freshly palloc'd value; if so, we copy the value
+ *	  to the context we want it in.
+ *
  *
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.73 2001/01/24 19:42:54 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/executor/nodeAgg.c,v 1.74 2001/02/15 21:47:08 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
-- 
GitLab