If you are fetching very large data sets using spi_exec_query, you should be aware that these
will all go into memory. You can avoid this by using
spi_query/spi_fetchrow as illustrated earlier.

A similar problem occurs if a set-returning function
passes a large set of rows back to PostgreSQL via return. You can avoid this problem too by
instead using return_next for each
row returned, as shown previously.