summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2020-03-17 01:05:29 +0000
committerTom Lane2020-03-17 01:05:54 +0000
commit819d5525744bff600b6073804a7a5eb7a9342a8b (patch)
tree8c3b9ee9f3aabd2452c32292d7865870ca8c4d1d /src/include
parenta6b5ddf64ce24532c69a24f1b3e13dbaa81ccbba (diff)
Avoid holding a directory FD open across assorted SRF calls.
This extends the fixes made in commit 085b6b667 to other SRFs with the same bug, namely pg_logdir_ls(), pgrowlocks(), pg_timezone_names(), pg_ls_dir(), and pg_tablespace_databases(). Also adjust various comments and documentation to warn against expecting to clean up resources during a ValuePerCall SRF's final call. Back-patch to all supported branches, since these functions were all born broken. Justin Pryzby, with cosmetic tweaks by me Discussion: https://postgr.es/m/20200308173103.GC1357@telsasoft.com
Diffstat (limited to 'src/include')
-rw-r--r--src/include/funcapi.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/include/funcapi.h b/src/include/funcapi.h
index 01aa208c5ee..4b454bc5066 100644
--- a/src/include/funcapi.h
+++ b/src/include/funcapi.h
@@ -246,7 +246,7 @@ extern TupleTableSlot *TupleDescGetSlot(TupleDesc tupdesc);
/*----------
* Support for Set Returning Functions (SRFs)
*
- * The basic API for SRFs looks something like:
+ * The basic API for SRFs using ValuePerCall mode looks something like this:
*
* Datum
* my_Set_Returning_Function(PG_FUNCTION_ARGS)
@@ -283,6 +283,17 @@ extern TupleTableSlot *TupleDescGetSlot(TupleDesc tupdesc);
* SRF_RETURN_DONE(funcctx);
* }
*
+ * NOTE: there is no guarantee that a SRF using ValuePerCall mode will be
+ * run to completion; for example, a query with LIMIT might stop short of
+ * fetching all the rows. Therefore, do not expect that you can do resource
+ * cleanup just before SRF_RETURN_DONE(). You need not worry about releasing
+ * memory allocated in multi_call_memory_ctx, but holding file descriptors or
+ * other non-memory resources open across calls is a bug. SRFs that need
+ * such resources should not use these macros, but instead populate a
+ * tuplestore during a single call, and return that using SFRM_Materialize
+ * mode (see fmgr/README). Alternatively, set up a callback to release
+ * resources at query shutdown, using RegisterExprContextCallback().
+ *
*----------
*/