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

From Thomas Hallgren
Subject Recursive calls to functions that return sets
Date
Msg-id 44215FDF.6020806@tada.se
Whole thread Raw
Responses Re: Recursive calls to functions that return sets  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-hackers
Imagine the following scenario:

Function 'A' returns SETOF 'x'. It will issue a query using SPI that 
calls function 'B'. This function returns SETOF 'y'.
Each tuple of 'x' is formed from some data in 'y'.
There will be millions of tuples so building a set of 'y' in memory is 
not an option.

What would the recommended use of MemoryContexts in an SRF function be 
in order to make this work? The SPI_connect must be issued during the 
SRF_IS_FIRST_CALL() phase. The Portal that it creates must remain alive 
until it's time for the SRF_RETURN_DONE(). What would the recommended 
approach be to accomplish this efficiently (and without introducing a 
major memory leak)?

The problem I'm trying to solve is a generic one. It's very possible 
that the recursion is is of arbitrary depth.

Regards,
Thomas Hallgren



pgsql-hackers by date:

Previous
From: "Jonah H. Harris"
Date:
Subject: Request from Tom--offlist
Next
From: Mark Wong
Date:
Subject: Re: Patch Submission Guidelines