public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ed Behn <[email protected]>
To: [email protected]
Subject: Persistent data across SETOF calls
Date: Sat, 21 Mar 2026 08:22:38 -0400
Message-ID: <CAJBL5DNPYDw84qDohS5CMXOLESsozV7QNJ6NwS1M66+tvHmzdw@mail.gmail.com> (raw)

Good day-
    I maintain the PL/Haskell language handler. Typically, the handler
compiles function code and stores the compiled data in the fn_extra field
of FmgrInfo. The fn_extra field persists from one call to the next within a
query meaning the expensive compilation only needs to happen once per
query.

    However, when calling a set-returning function multiple times in a
query, there appears to be no way to carry data from one set to another.
This is because the fn_extra field stores the FuncCallContext structure.
While the user_fctx field of the FuncCallContext structure persists from
one call to the next, it is NULLed out at the end of a set.

    For example, if there is a table, t, with a column, i, and a
set-returning function, func, the following query is very inefficient:

    SELECT *
    FROM t, func(i)

This is because the function is recompiled for each row of t.

Is there a way around this? Ideally, there would be a field that
persists from one set to another within a query.

Thank you for any help you can provide.
              -Ed


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: Persistent data across SETOF calls
  In-Reply-To: <CAJBL5DNPYDw84qDohS5CMXOLESsozV7QNJ6NwS1M66+tvHmzdw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox