8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
15
-
16
-
17
15
#include "postgres.h"
18
16
19
17
#include "access/heapam.h"
37
35
* called 'resjunk'. If the value of this attribute is true then the
38
36
* corresponding attribute is a "junk" attribute.
39
37
*
40
- * When we initialize a plan we call 'ExecInitJunkFilter' to create
38
+ * When we initialize a plan we call 'ExecInitJunkFilter' to create
41
39
* and store the appropriate information in the 'es_junkFilter' attribute of
42
40
* EState.
43
41
*
63
61
JunkFilter *
64
62
ExecInitJunkFilter (List * targetList ,TupleDesc tupType )
65
63
{
64
+ MemoryContext oldContext ;
65
+ MemoryContext junkContext ;
66
66
JunkFilter * junkfilter ;
67
67
List * cleanTargetList ;
68
68
int len ,
@@ -75,9 +75,21 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
75
75
bool resjunk ;
76
76
AttrNumber cleanResno ;
77
77
AttrNumber * cleanMap ;
78
- Size size ;
79
78
Node * expr ;
80
79
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
+
81
93
/* ---------------------
82
94
* First find the "clean" target list, i.e. all the entries
83
95
* in the original target list which have a false 'resjunk'
@@ -166,7 +178,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
166
178
cleanLength = ExecTargetListLength (cleanTargetList );
167
179
168
180
/* ---------------------
169
- * Now calculate the "map" between the originaltuples attributes
181
+ * Now calculate the "map" between the originaltuple's attributes
170
182
* and the "clean" tuple's attributes.
171
183
*
172
184
* The "map" is an array of "cleanLength" attribute numbers, i.e.
@@ -177,8 +189,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
177
189
*/
178
190
if (cleanLength > 0 )
179
191
{
180
- size = cleanLength * sizeof (AttrNumber );
181
- cleanMap = (AttrNumber * )palloc (size );
192
+ cleanMap = (AttrNumber * )palloc (cleanLength * sizeof (AttrNumber ));
182
193
cleanResno = 1 ;
183
194
foreach (t ,targetList )
184
195
{
@@ -226,7 +237,7 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
226
237
cleanMap = NULL ;
227
238
228
239
/* ---------------------
229
- * Finally create and initialize the JunkFilter.
240
+ * Finally create and initialize the JunkFilter struct .
230
241
* ---------------------
231
242
*/
232
243
junkfilter = makeNode (JunkFilter );
@@ -238,20 +249,36 @@ ExecInitJunkFilter(List *targetList, TupleDesc tupType)
238
249
junkfilter -> jf_cleanLength = cleanLength ;
239
250
junkfilter -> jf_cleanTupType = cleanTupType ;
240
251
junkfilter -> jf_cleanMap = cleanMap ;
252
+ junkfilter -> jf_junkContext = junkContext ;
253
+
254
+ MemoryContextSwitchTo (oldContext );
241
255
242
256
return junkfilter ;
257
+ }
243
258
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 );
244
273
}
245
274
246
275
/*-------------------------------------------------------------------------
247
276
* ExecGetJunkAttribute
248
277
*
249
278
* 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 valueand isNull flag of this attribute.
251
280
*
252
281
* It returns false iff no junk attribute with such name was found.
253
- *
254
- * NOTE: isNull might be NULL !
255
282
*-------------------------------------------------------------------------
256
283
*/
257
284
bool
@@ -304,7 +331,7 @@ ExecGetJunkAttribute(JunkFilter *junkfilter,
304
331
* ---------------------
305
332
*/
306
333
tuple = slot -> val ;
307
- tupType = ( TupleDesc ) junkfilter -> jf_tupType ;
334
+ tupType = junkfilter -> jf_tupType ;
308
335
309
336
* value = heap_getattr (tuple ,resno ,tupType ,isNull );
310
337
@@ -328,7 +355,6 @@ ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
328
355
int cleanLength ;
329
356
bool isNull ;
330
357
int i ;
331
- Size size ;
332
358
Datum * values ;
333
359
char * nulls ;
334
360
Datum values_array [64 ];
@@ -340,8 +366,8 @@ ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
340
366
*/
341
367
tuple = slot -> val ;
342
368
343
- tupType = ( TupleDesc ) junkfilter -> jf_tupType ;
344
- cleanTupType = ( TupleDesc ) junkfilter -> jf_cleanTupType ;
369
+ tupType = junkfilter -> jf_tupType ;
370
+ cleanTupType = junkfilter -> jf_cleanTupType ;
345
371
cleanLength = junkfilter -> jf_cleanLength ;
346
372
cleanMap = junkfilter -> jf_cleanMap ;
347
373
@@ -363,11 +389,8 @@ ExecRemoveJunk(JunkFilter *junkfilter, TupleTableSlot *slot)
363
389
*/
364
390
if (cleanLength > 64 )
365
391
{
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 ));
371
394
}
372
395
else
373
396
{