PostgreSQL documents it's Set Returning Functions with C extensions like this,
C-language functions have two options for returning sets (multiple rows).
- In one method, called
ValuePerCall
mode, a set-returning function is called repeatedly (passing the same arguments each time) and it returns one new row on each call, until it has no more rows to return and signals that by returning NULL. The set-returning function (SRF) must therefore save enough state across calls to remember what it was doing and return the correct next item on each call.- In the other method, called
Materialize
mode, an SRF fills and returns a tuplestore object containing its entire result; then only one call occurs for the whole result, and no inter-call state is needed.
If you're optimizing for execution speed, which is faster ValuePerCall
or Materialize
mode? Obviously Materialize mode will take more memory but it seems like it should faster if your goal is to return a whole set, I don't see that documented anywhere though.
These seem to be documented in the code as Set Returning Function Mode SFRM_ValuePerCall
and SFRM_Materialize
.