88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.24 2001/01/24 19:42:53 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/executor/execJunk.c,v 1.25 2001/01/29 00:39:17 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
15-
16-
1715#include "postgres.h"
1816
1917#include "access/heapam.h"
3735 * called 'resjunk'. If the value of this attribute is true then the
3836 * corresponding attribute is a "junk" attribute.
3937 *
40- * When we initialize a plan we call 'ExecInitJunkFilter' to create
38+ * When we initialize a plan we call 'ExecInitJunkFilter' to create
4139 * and store the appropriate information in the 'es_junkFilter' attribute of
4240 * EState.
4341 *
6361JunkFilter *
6462ExecInitJunkFilter (List * targetList , TupleDesc tupType )
6563{
64+ MemoryContext oldContext ;
65+ MemoryContext junkContext ;
6666 JunkFilter * junkfilter ;
6767 List * cleanTargetList ;
6868 int len ,
@@ -75,9 +75,21 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
7575 bool resjunk ;
7676 AttrNumber cleanResno ;
7777 AttrNumber * cleanMap ;
78- Size size ;
7978 Node * expr ;
8079
80+ /*
81+ * Make a memory context that will hold the JunkFilter as well as all
82+ * the subsidiary structures we are about to create. We use smaller-
83+ * than-default sizing parameters since we don't expect a very large
84+ * volume of stuff here.
85+ */
86+ junkContext = AllocSetContextCreate (CurrentMemoryContext ,
87+ "JunkFilterContext" ,
88+ 1024 ,
89+ 1024 ,
90+ ALLOCSET_DEFAULT_MAXSIZE );
91+ oldContext = MemoryContextSwitchTo (junkContext );
92+
8193 /* ---------------------
8294 * First find the "clean" target list, i.e. all the entries
8395 * in the original target list which have a false 'resjunk'
@@ -166,7 +178,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
166178 cleanLength = ExecTargetListLength (cleanTargetList );
167179
168180 /* ---------------------
169- * Now calculate the "map" between the original tuples attributes
181+ * Now calculate the "map" between the original tuple's attributes
170182 * and the "clean" tuple's attributes.
171183 *
172184 * The "map" is an array of "cleanLength" attribute numbers, i.e.
@@ -177,8 +189,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
177189 */
178190 if (cleanLength > 0 )
179191 {
180- size = cleanLength * sizeof (AttrNumber );
181- cleanMap = (AttrNumber * ) palloc (size );
192+ cleanMap = (AttrNumber * ) palloc (cleanLength * sizeof (AttrNumber ));
182193 cleanResno = 1 ;
183194 foreach (t , targetList )
184195 {
@@ -226,7 +237,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
226237 cleanMap = NULL ;
227238
228239 /* ---------------------
229- * Finally create and initialize the JunkFilter.
240+ * Finally create and initialize the JunkFilter struct .
230241 * ---------------------
231242 */
232243 junkfilter = makeNode (JunkFilter );
@@ -238,20 +249,36 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
238249 junkfilter -> jf_cleanLength = cleanLength ;
239250 junkfilter -> jf_cleanTupType = cleanTupType ;
240251 junkfilter -> jf_cleanMap = cleanMap ;
252+ junkfilter -> jf_junkContext = junkContext ;
253+
254+ MemoryContextSwitchTo (oldContext );
241255
242256 return junkfilter ;
257+ }
243258
259+ /*-------------------------------------------------------------------------
260+ * ExecFreeJunkFilter
261+ *
262+ * Release the data structures created by ExecInitJunkFilter.
263+ *-------------------------------------------------------------------------
264+ */
265+ void
266+ ExecFreeJunkFilter (JunkFilter * junkfilter )
267+ {
268+ /*
269+ * Since the junkfilter is inside its own context, we just have to
270+ * delete the context and we're set.
271+ */
272+ MemoryContextDelete (junkfilter -> jf_junkContext );
244273}
245274
246275/*-------------------------------------------------------------------------
247276 * ExecGetJunkAttribute
248277 *
249278 * Given a tuple (slot), the junk filter and a junk attribute's name,
250- * extract & return the value of this attribute.
279+ * extract & return the value and isNull flag of this attribute.
251280 *
252281 * It returns false iff no junk attribute with such name was found.
253- *
254- * NOTE: isNull might be NULL !
255282 *-------------------------------------------------------------------------
256283 */
257284bool
@@ -304,7 +331,7 @@ ExecGetJunkAttribute(JunkFilter *junkfilter,
304331 * ---------------------
305332 */
306333 tuple = slot -> val ;
307- tupType = ( TupleDesc ) junkfilter -> jf_tupType ;
334+ tupType = junkfilter -> jf_tupType ;
308335
309336 * value = heap_getattr (tuple , resno , tupType , isNull );
310337
@@ -328,7 +355,6 @@ ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
328355 int cleanLength ;
329356 bool isNull ;
330357 int i ;
331- Size size ;
332358 Datum * values ;
333359 char * nulls ;
334360 Datum values_array [64 ];
@@ -340,8 +366,8 @@ ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
340366 */
341367 tuple = slot -> val ;
342368
343- tupType = ( TupleDesc ) junkfilter -> jf_tupType ;
344- cleanTupType = ( TupleDesc ) junkfilter -> jf_cleanTupType ;
369+ tupType = junkfilter -> jf_tupType ;
370+ cleanTupType = junkfilter -> jf_cleanTupType ;
345371 cleanLength = junkfilter -> jf_cleanLength ;
346372 cleanMap = junkfilter -> jf_cleanMap ;
347373
@@ -363,11 +389,8 @@ ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
363389 */
364390 if (cleanLength > 64 )
365391 {
366- size = cleanLength * sizeof (Datum );
367- values = (Datum * ) palloc (size );
368-
369- size = cleanLength * sizeof (char );
370- nulls = (char * ) palloc (size );
392+ values = (Datum * ) palloc (cleanLength * sizeof (Datum ));
393+ nulls = (char * ) palloc (cleanLength * sizeof (char ));
371394 }
372395 else
373396 {
0 commit comments