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


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
      choose an index scan if your joining column's datatypes do not
      match

Reply via email to