Sample Header Ad - 728x90

C Extension: Is it faster to return a set with ValuePerCall or Materialize mode?

0 votes
1 answer
272 views
PostgreSQL documents it's [Set Returning Functions with C extensions like this](https://www.postgresql.org/docs/current/xfunc-c.html) , > 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](https://doxygen.postgresql.org/execnodes_8h.html#ac46fbb67a00d131ce2173bc6b85164f8) SFRM_ValuePerCall and SFRM_Materialize.
Asked by Evan Carroll (65502 rep)
Oct 30, 2021, 05:57 PM
Last activity: Nov 3, 2021, 08:19 AM