Hello,
I would like to propose a modification to the internal_get_result_type
function, which is called from *get_call_result_type*. Specifically, I
recommend altering it to return a copy of *rsinfo->expectedDesc*.

Currently, callers are responsible for copying the tuple descriptor
returned from *get_call_result_type* before assigning it to rsinfo->setDesc
as part of set-returning functions in mode *SFRM_Materialize *if not copied
then it can lead to unexpected behavior because rsinfo->expectedDesc will
be unintentionally freed at the end of ExecMakeTableFunctionResult as
rsinfo->setDesc holds its reference. This can be overlooked, unless a
user-defined function (UDF) is invoked multiple times within the same query.

*Example*: Queries involving lateral joins with user-defined functions
(UDFs).

For your convenience, I have created a GitHub repository demonstrating the
issue with a C extension: https://github.com/narayana-dev/srfbug

Additionally, I have attached the patch file for your review.

I look forward to your feedback.

Best regards,
Lakshmi Narayana Velayudam

Attachment: copy_tup_desc.patch
Description: Binary data

Reply via email to