Recursive calls to functions that return sets

From: Thomas Hallgren <thomas(at)tada(dot)se>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Recursive calls to functions that return sets
Date: 2006-03-22 14:31:59
Message-ID: 44215FDF.6020806@tada.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Wong 2006-03-22 15:52:32 Re: Patch Submission Guidelines
Previous Message Jonah H. Harris 2006-03-22 13:17:35 Request from Tom--offlist