Fix failure in function cache entry hashing during validation mode. When cached_function_compile() is called with forValidator = true, the passed FunctionCallInfo is one that the caller set up specially, and it's typically pretty incomplete. compute_function_hashkey() was careless about this and would call get_call_result_type() if asked to, which would fail in any but the simplest cases. We'd managed not to notice in the pre-existing use-cases because plpgsql and functions.c don't pass includeResultType and forValidator both true at the same time; but plpython does, so it would reach this failure in cases such as polymorphic argument types. plpython does not yet support polymorphic arguments, and has no test cases about them, so we did not see that the intended error message had degraded to an internal failure in get_call_result_type().
To fix, just skip trying to fill the result type tupdesc when in validation mode. This leads to building a hashtable entry that will never match any real calls, but that's true in a lot of other validation cases as well. The root cause here is lack of clarity about what we expect the passed FunctionCallInfo to contain in validation mode, so add comments specifying that. Also add some plpython test cases showing the expected error reports. Backpatch to v18 where funccache.c was introduced. This problem's not reachable in the core code in v18, since plpython didn't use funccache.c then. But extensions could perhaps be using funccache.c as of v18, and they might hit it. Author: Tom Lane <[email protected]> Reviewed-by: shihao zhong <[email protected]> Discussion: https://postgr.es/m/[email protected] Backpatch-through: 18 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/a4bc92a82c4e362e5b1dad83f86e5e1d93a970c5 Modified Files -------------- src/backend/utils/cache/funccache.c | 15 ++++++++++++--- src/pl/plpython/expected/plpython_error.out | 10 ++++++++++ src/pl/plpython/sql/plpython_error.sql | 10 ++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-)
