* Copyright (c) 2002-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.80 2008/01/01 19:45:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.81 2008/03/25 19:26:53 neilc Exp $
*
*-------------------------------------------------------------------------
*/
hash_seq_init(&hash_seq, prepared_queries);
while ((prep_stmt = hash_seq_search(&hash_seq)) != NULL)
{
- HeapTuple tuple;
Datum values[5];
bool nulls[5];
prep_stmt->plansource->num_params);
values[4] = BoolGetDatum(prep_stmt->from_sql);
- tuple = heap_form_tuple(tupdesc, values, nulls);
-
/* switch to appropriate context while storing the tuple */
MemoryContextSwitchTo(per_query_ctx);
- tuplestore_puttuple(tupstore, tuple);
+ tuplestore_putvalues(tupstore, tupdesc, values, nulls);
}
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.226 2008/01/01 19:45:49 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.227 2008/03/25 19:26:53 neilc Exp $
*
*-------------------------------------------------------------------------
*/
for (;;)
{
Datum result;
- HeapTuple tuple;
CHECK_FOR_INTERRUPTS();
*/
tmptup.t_len = HeapTupleHeaderGetDatumLength(td);
tmptup.t_data = td;
- tuple = &tmptup;
+
+ oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
+ tuplestore_puttuple(tupstore, &tmptup);
}
else
{
- tuple = heap_form_tuple(tupdesc, &result, &fcinfo.isnull);
+ oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
+ tuplestore_putvalues(tupstore, tupdesc, &result, &fcinfo.isnull);
}
-
- oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
- tuplestore_puttuple(tupstore, tuple);
MemoryContextSwitchTo(oldcontext);
/*
int natts = expectedDesc->natts;
Datum *nulldatums;
bool *nullflags;
- HeapTuple tuple;
MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
nulldatums = (Datum *) palloc0(natts * sizeof(Datum));
nullflags = (bool *) palloc(natts * sizeof(bool));
memset(nullflags, true, natts * sizeof(bool));
- tuple = heap_form_tuple(expectedDesc, nulldatums, nullflags);
MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
- tuplestore_puttuple(tupstore, tuple);
+ tuplestore_putvalues(tupstore, expectedDesc, nulldatums, nullflags);
}
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.106 2008/01/01 19:45:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.107 2008/03/25 19:26:53 neilc Exp $
*
*-------------------------------------------------------------------------
*/
while ((hentry = hash_seq_search(&hash_seq)) != NULL)
{
Portal portal = hentry->portal;
- HeapTuple tuple;
Datum values[6];
bool nulls[6];
values[4] = BoolGetDatum(portal->cursorOptions & CURSOR_OPT_SCROLL);
values[5] = TimestampTzGetDatum(portal->creation_time);
- tuple = heap_form_tuple(tupdesc, values, nulls);
-
/* switch to appropriate context while storing the tuple */
MemoryContextSwitchTo(per_query_ctx);
- tuplestore_puttuple(tupstore, tuple);
+ tuplestore_putvalues(tupstore, tupdesc, values, nulls);
}
/* clean up and return the tuplestore */
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.37 2008/03/10 20:06:27 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.38 2008/03/25 19:26:53 neilc Exp $
*
*-------------------------------------------------------------------------
*/
/*
* "Standard" case to copy from a HeapTuple. This is actually now somewhat
* deprecated, but not worth getting rid of in view of the number of callers.
- * (Consider adding something that takes a tupdesc+values/nulls arrays so
- * that we can use heap_form_minimal_tuple() and avoid a copy step.)
*/
void
tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
tuplestore_puttuple_common(state, (void *) tuple);
}
+/*
+ * Similar to tuplestore_puttuple(), but start from the values + nulls
+ * array. This avoids requiring that the caller construct a HeapTuple,
+ * saving a copy.
+ */
+void
+tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
+ Datum *values, bool *isnull)
+{
+ MinimalTuple tuple;
+
+ tuple = heap_form_minimal_tuple(tdesc, values, isnull);
+
+ tuplestore_puttuple_common(state, (void *) tuple);
+}
+
static void
tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
{
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/tuplestore.h,v 1.22 2008/01/01 19:45:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/tuplestore.h,v 1.23 2008/03/25 19:26:53 neilc Exp $
*
*-------------------------------------------------------------------------
*/
extern void tuplestore_puttupleslot(Tuplestorestate *state,
TupleTableSlot *slot);
extern void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple);
+extern void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc,
+ Datum *values, bool *isnull);
/* tuplestore_donestoring() used to be required, but is no longer used */
#define tuplestore_donestoring(state) ((void) 0)
/**********************************************************************
* plperl.c - perl as a procedural language for PostgreSQL
*
- * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.136 2008/01/23 00:55:47 adunstan Exp $
+ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.137 2008/03/25 19:26:53 neilc Exp $
*
**********************************************************************/
FunctionCallInfo fcinfo;
ReturnSetInfo *rsi;
MemoryContext old_cxt;
- HeapTuple tuple;
if (!sv)
return;
if (prodesc->fn_retistuple)
{
+ HeapTuple tuple;
+
tuple = plperl_build_tuple_result((HV *) SvRV(sv),
current_call_data->attinmeta);
+
+ /* Make sure to store the tuple in a long-lived memory context */
+ MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
+ tuplestore_puttuple(current_call_data->tuple_store, tuple);
+ MemoryContextSwitchTo(old_cxt);
}
else
{
isNull = true;
}
- tuple = heap_form_tuple(current_call_data->ret_tdesc, &ret, &isNull);
+ /* Make sure to store the tuple in a long-lived memory context */
+ MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
+ tuplestore_putvalues(current_call_data->tuple_store,
+ current_call_data->ret_tdesc,
+ &ret, &isNull);
+ MemoryContextSwitchTo(old_cxt);
}
- /* Make sure to store the tuple in a long-lived memory context */
- MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
- tuplestore_puttuple(current_call_data->tuple_store, tuple);
- MemoryContextSwitchTo(old_cxt);
-
MemoryContextReset(current_call_data->tmp_cxt);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.202 2008/01/01 19:46:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.203 2008/03/25 19:26:54 neilc Exp $
*
*-------------------------------------------------------------------------
*/
exec_stmt_return_next(PLpgSQL_execstate *estate,
PLpgSQL_stmt_return_next *stmt)
{
- TupleDesc tupdesc;
- int natts;
- HeapTuple tuple;
- bool free_tuple = false;
+ TupleDesc tupdesc;
+ int natts;
+ MemoryContext oldcxt;
+ HeapTuple tuple = NULL;
+ bool free_tuple = false;
if (!estate->retisset)
ereport(ERROR,
tupdesc->attrs[0]->atttypmod,
isNull);
- tuple = heap_form_tuple(tupdesc, &retval, &isNull);
-
- free_tuple = true;
+ oldcxt = MemoryContextSwitchTo(estate->tuple_store_cxt);
+ tuplestore_putvalues(estate->tuple_store, tupdesc,
+ &retval, &isNull);
+ MemoryContextSwitchTo(oldcxt);
}
break;
default:
elog(ERROR, "unrecognized dtype: %d", retvar->dtype);
- tuple = NULL; /* keep compiler quiet */
break;
}
}
tupdesc->attrs[0]->atttypmod,
isNull);
- tuple = heap_form_tuple(tupdesc, &retval, &isNull);
-
- free_tuple = true;
+ oldcxt = MemoryContextSwitchTo(estate->tuple_store_cxt);
+ tuplestore_putvalues(estate->tuple_store, tupdesc,
+ &retval, &isNull);
+ MemoryContextSwitchTo(oldcxt);
exec_eval_cleanup(estate);
}
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("RETURN NEXT must have a parameter")));
- tuple = NULL; /* keep compiler quiet */
}
if (HeapTupleIsValid(tuple))
{
- MemoryContext oldcxt;
-
oldcxt = MemoryContextSwitchTo(estate->tuple_store_cxt);
tuplestore_puttuple(estate->tuple_store, tuple);
MemoryContextSwitchTo(oldcxt);