From 1d812a98b47da94ad274dcac682c5d2c014aae16 Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Tue, 25 Mar 2008 19:26:54 +0000 Subject: Add a new tuplestore API function, tuplestore_putvalues(). This is identical to tuplestore_puttuple(), except it operates on arrays of Datums + nulls rather than a fully-formed HeapTuple. In several places that use the tuplestore API, this means we can avoid creating a HeapTuple altogether, saving a copy. --- src/pl/plperl/plperl.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/pl/plperl/plperl.c') diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 452c69cec73..3ce8f60c262 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1,7 +1,7 @@ /********************************************************************** * 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 $ * **********************************************************************/ @@ -1869,7 +1869,6 @@ plperl_return_next(SV *sv) FunctionCallInfo fcinfo; ReturnSetInfo *rsi; MemoryContext old_cxt; - HeapTuple tuple; if (!sv) return; @@ -1944,8 +1943,15 @@ plperl_return_next(SV *sv) 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 { @@ -1967,14 +1973,14 @@ plperl_return_next(SV *sv) 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); } -- cgit v1.2.3