*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.51 1999/05/25 16:06:35 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.52 1999/06/12 14:05:36 momjian Exp $
*
* NOTES
* The old interface functions have been converted to macros
#include
#include
+#ifdef FREE_TUPLE_MEMORY
+#include
+#include
+#endif
+
#ifndef HAVE_MEMMOVE
#include
#else
int i;
int numberOfAttributes = tupleDesc->natts;
Form_pg_attribute *att = tupleDesc->attrs;
+#ifdef FREE_TUPLE_MEMORY
+ bool free_tuple_memory = pg_options[OPT_FREE_TUPLE_MEMORY];
+#endif
if (bit != NULL)
{
*infomask |= HEAP_HASVARLENA;
data_length = VARSIZE(DatumGetPointer(value[i]));
memmove(data, DatumGetPointer(value[i]), data_length);
+#ifdef FREE_TUPLE_MEMORY
+ /* try to pfree value[i] - dz */
+ if (free_tuple_memory &&
+ PortalHeapMemoryIsValid(CurrentMemoryContext,
+ (Pointer) value[i])) {
+ pfree(value[i]);
+ }
+#endif
break;
case sizeof(char):
*data = att[i]->attbyval ?
*((int32 *) value[i]));
break;
default:
- memmove(data, DatumGetPointer(value[i]),
- att[i]->attlen);
+ memmove(data, DatumGetPointer(value[i]), att[i]->attlen);
+#ifdef FREE_TUPLE_MEMORY
+ /* try to pfree value[i] - dz */
+ if (free_tuple_memory &&
+ PortalHeapMemoryIsValid(CurrentMemoryContext,
+ (Pointer) value[i])) {
+ pfree(value[i]);
+ }
+#endif
break;
}
data = (char *) att_addlength((long) data, att[i]->attlen, value[i]);
#include "utils/syscache.h"
#include "optimizer/clauses.h"
+#ifdef FREE_TUPLE_MEMORY
+#include
+#include
+#endif
+
/*
* AggFuncInfo -
* keeps the transition functions information around
isNull1 = FALSE,
isNull2 = FALSE;
bool qual_result;
-
+#ifdef FREE_TUPLE_MEMORY
+ bool free_tuple_memory = pg_options[OPT_FREE_TUPLE_MEMORY];
+#endif
/* ---------------------
* get state info from node
for (;;)
{
TupleTableSlot *outerslot;
+#ifdef FREE_TUPLE_MEMORY
+ Oid valueType;
+ bool isByValue = 0;
+#endif
isNull = isNull1 = isNull2 = 0;
outerslot = ExecProcNode(outerPlan, (Plan *) node);
newVal = ExecEvalExpr(aggref->target, econtext,
&isNull, &isDone);
}
+#ifdef FREE_TUPLE_MEMORY
+ if (free_tuple_memory) {
+ switch (nodeTag(aggref->target)) {
+ case T_Const:
+ isByValue = ((Const*) (aggref->target))->constbyval;
+ break;
+ case T_Var:
+ valueType = ((Var*) (aggref->target))->vartype;
+ isByValue = typeByVal(typeidType(valueType));
+ break;
+ case T_Array:
+ isByValue = ((Array*)(aggref->target))->arrayelembyval;
+ break;
+ case T_ArrayRef:
+ isByValue =((ArrayRef*)(aggref->target))->refelembyval;
+ break;
+ case T_Expr:
+ valueType = ((Expr*) (aggref->target))->typeOid;
+ isByValue = typeByVal(typeidType(valueType));
+ break;
+ default:
+ break;
+ }
+ }
+#endif
if (isNull && !aggref->usenulls)
continue; /* ignore this tuple for this agg */
(FmgrValues *) args, &isNull2);
Assert(!isNull2);
}
+
+#ifdef FREE_TUPLE_MEMORY
+ /* try to pfree newVal if not isByValue - dz */
+ if (free_tuple_memory && !isByValue &&
+ PortalHeapMemoryIsValid(CurrentMemoryContext,
+ (Pointer) newVal))
+ {
+ pfree(newVal);
+ }
+#endif
}
/*
"syslog", /* use syslog for error messages */
"hostlookup", /* enable hostname lookup in ps_status */
"showportnumber", /* show port number in ps_status */
+#ifdef FREE_TUPLE_MEMORY
+ "free_tuple_memory", /* try to pfree memory for each tuple */
+#endif
/* NUM_PG_OPTIONS */ /* must be the last item of enum */
};
}
/*
- * Local variables:
- * tab-width: 4
- * c-indent-level: 4
- * c-basic-offset: 4
+ * Local Variables:
+ * tab-width: 4
+ * c-indent-level: 4
+ * c-basic-offset: 4
* End:
*/
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.19 1999/05/25 16:12:55 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.20 1999/06/12 14:05:39 momjian Exp $
*
*-------------------------------------------------------------------------
*/
}
}
+#ifdef FREE_TUPLE_MEMORY
+/*
+ * PortalHeapMemoryIsValid --
+ *
+ * Check if a pointer is allocated in a memory context.
+ *
+ */
+bool
+PortalHeapMemoryIsValid(MemoryContext context, Pointer pointer)
+{
+ HeapMemoryBlock block = HEAPMEMBLOCK((PortalHeapMemory) context);
+
+ AssertState(PointerIsValid(block));
+
+ return (AllocSetContains(&block->setData, pointer));
+}
+#endif
+
/* ----------------
* PortalHeapMemoryRealloc
* ----------------
*
* Copyright (c) 1994, Regents of the University of California
*
- * $Id: portal.h,v 1.13 1999/05/25 16:14:57 momjian Exp $
+ * $Id: portal.h,v 1.14 1999/06/12 14:05:40 momjian Exp $
*
*-------------------------------------------------------------------------
*/
extern PortalVariableMemory PortalGetVariableMemory(Portal portal);
extern PortalHeapMemory PortalGetHeapMemory(Portal portal);
+#ifdef FREE_TUPLE_MEMORY
+bool PortalHeapMemoryIsValid(MemoryContext context, Pointer pointer);
+#endif
+
/* estimate of the maximum number of open portals a user would have,
* used in initially sizing the PortalHashTable in EnablePortalManager()
*/
OPT_SYSLOG, /* use syslog for error messages */
OPT_HOSTLOOKUP, /* enable hostname lookup in ps_status */
OPT_SHOWPORTNUMBER, /* show port number in ps_status */
+#ifdef FREE_TUPLE_MEMORY
+ OPT_FREE_TUPLE_MEMORY, /* try to pfree memory for each tuple */
+#endif
NUM_PG_OPTIONS /* must be the last item of enum */
};
#endif /* TRACE_H */
/*
- * Local variables:
- * tab-width: 4
- * c-indent-level: 4
- * c-basic-offset: 4
+ * Local Variables:
+ * tab-width: 4
+ * c-indent-level: 4
+ * c-basic-offset: 4
* End:
*/