diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-11-29 11:46:33 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-11-29 11:46:33 -0500 |
commit | 7715a3c244507a52e64fbfe36547ec09eafd4af0 (patch) | |
tree | 847e0adf9d477a8d5045c62bf4dbd10aa09aae0b | |
parent | 0224646beec657fb3a7791d237293ad4caea3255 (diff) | |
download | postgresql-7715a3c244507a52e64fbfe36547ec09eafd4af0.tar.gz postgresql-7715a3c244507a52e64fbfe36547ec09eafd4af0.zip |
Prevent clobbering of utility statements in SQL function caches.
This is an oversight in commit 7c337b6b5: I apparently didn't think
about the possibility of a SQL function being executed multiple
times within a query. In that case, functions.c's primitive caching
mechanism allows the same utility parse tree to be presented for
execution more than once. We have to tell ProcessUtility to make
a working copy of the parse tree, or bad things happen.
Normally I'd add a regression test, but I think the reported crasher
is dependent on some rather random implementation choices that are
nowhere near functions.c, so its usefulness as a long-lived test
feels questionable. In any case, this fix is clearly correct given
the design choices of 7c337b6b5.
Per bug #17702 from Xin Wen. Thanks to Daniel Gustafsson for
analysis. Back-patch to v14 where the faulty commit came in
(before that, the responsibility for copying scribble-able
utility parse trees lay elsewhere).
Discussion: https://postgr.es/m/17702-ad24fdcdd1e9047a@postgresql.org
-rw-r--r-- | src/backend/executor/functions.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index db5191d3295..e8ab5be0bca 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -886,7 +886,7 @@ postquel_getnext(execution_state *es, SQLFunctionCachePtr fcache) { ProcessUtility(es->qd->plannedstmt, fcache->src, - false, + true, /* protect function cache's parsetree */ PROCESS_UTILITY_QUERY, es->qd->params, es->qd->queryEnv, |