Re: Function scan FDW pushdown

From: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
To: Alexander Pyhalov <a(dot)pyhalov(at)postgrespro(dot)ru>
Cc: solaimurugan vellaipandiyan <drsolaimurugan(dot)v(at)gmail(dot)com>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, g(dot)kashkin(at)postgrespro(dot)ru, Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Function scan FDW pushdown
Date: 2026-05-19 13:00:58
Message-ID: CAPpHfdvkPk0dLFbF-2DG7hV5zKNPcdyV4Xzj99chYiqAFtvh_Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, Alexander.

On Mon, May 18, 2026 at 11:06 PM Alexander Pyhalov
<a(dot)pyhalov(at)postgrespro(dot)ru> wrote:
> Hi. I am a bit confused about this comment (and code):
>
> /*
> * DirectModify on a foreign join: pass NIL/0 for
> the function
> * metadata. We don't currently push function
> RTEs through the
> * direct-modify path, so there are no whole-row
> Vars pointing at
> * function-RTE tuples to reconstruct.
> */
> tupdesc = get_tupdesc_for_join_scan_tuples(node,
> NIL, 0);
>
> We evidently go through this code path when executing example
>
> UPDATE remote_tbl r SET b=5 FROM UNNEST(array[box '((2,3),(-2,-3))']) AS
> t (bx) WHERE r.a = area(t.bx)
> RETURNING a,b;
>
> But don't need whole row var in returning list.... However, we still can
> step on this issue.

Yes, we go through this code path, and it works as long as whole-row
var is not needed.

> UPDATE remote_tbl r SET b=5 FROM UNNEST(array[box '((2,3),(-2,-3))'],
> array[int '1']) AS t (bx, i) WHERE r.a = area(t.bx)
> RETURNING a,b,t;
>
> ERROR: input of anonymous composite types is not implemented
> CONTEXT: whole-row reference to foreign table "t"

But if whole row var is actually used, then the assumption is broken.
So, we need to build a whole-row var anyway. I've fixed this in the
attached patch, and added your sample query as a regression test case.

------
Regards,
Alexander Korotkov
Supabase

Attachment Content-Type Size
v6-0001-postgres_fdw-push-down-FUNCTION-RTE-into-foreign-.patch application/octet-stream 56.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrei Lepikhov 2026-05-19 13:11:36 Re: Sequence Access Methods, round two
Previous Message Jim Jones 2026-05-19 12:08:36 Re: PSQL - prevent describe listing tables that are already in listed schemas