| From: | Lakshmi Narayana Velayudam <dev(dot)narayana(dot)v(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | Copy Tuple Desc in internal_get_result_type |
| Date: | 2025-05-24 07:16:37 |
| Message-ID: | CAA4pTnK+BgDYSMed+6=Y1_rtn7mNUgiPWF_6YiR=WT6o3pGRAw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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 | Content-Type | Size |
|---|---|---|
| copy_tup_desc.patch | application/octet-stream | 512 bytes |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | André Verwijs | 2025-05-24 07:22:59 | Testing PostgreSQL 18 beta ... |
| Previous Message | Feike Steenbergen | 2025-05-24 06:38:50 | Re: pg18: Virtual generated columns are not (yet) safe when superuser selects from them |