Re: Recursive calls to functions that return sets

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Thomas Hallgren <thomas(at)tada(dot)se>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Martijn van Oosterhout <kleptog(at)svana(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Recursive calls to functions that return sets
Date: 2006-03-22 17:34:55
Message-ID: 20060322173454.GA7100@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2006-03-22 17:36:19 Re: Recursive calls to functions that return sets
Previous Message Thomas Hallgren 2006-03-22 17:27:19 Re: Recursive calls to functions that return sets