Re: Recursive calls to functions that return sets - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Recursive calls to functions that return sets
Date
Msg-id 20060322173454.GA7100@surnet.cl
Whole thread Raw
In response to Re: Recursive calls to functions that return sets  (Thomas Hallgren <thomas@tada.se>)
List pgsql-hackers
Thomas Hallgren wrote:
> Recursive calls works in PL/Java. No problem there. But the larger the 
> set, the more memory it consumes. Do I read your answers correctly if I 
> conclude this is a known limitation when SPI is used? I.e. there's no 
> way to stream one row at a time without ever building the full set?

Hmm, are you using a tuplestore?  The PL/php code for return_next looks
like this:

ZEND_FUNCTION(return_next)
{   ... some stuff ...
   /* Use the per-query context so that the tuplestore survives */   oldcxt =
MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
   /* Form the tuple */   tup = plphp_srf_htup_from_zval(param, current_attinmeta, current_memcxt);
   /* First call?  Create the tuplestore. */   if (!current_tuplestore)       current_tuplestore =
tuplestore_begin_heap(true,false, work_mem);
 
   /* Save the tuple and clean up */   tuplestore_puttuple(current_tuplestore, tup);   heap_freetuple(tup);
   MemoryContextSwitchTo(oldcxt);
}

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


pgsql-hackers by date:

Previous
From: Thomas Hallgren
Date:
Subject: Re: Recursive calls to functions that return sets
Next
From: Tom Lane
Date:
Subject: Re: Recursive calls to functions that return sets