From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Chapman Flack <jcflack(at)acm(dot)org> |
Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: FmgrInfo allocation patterns (and PL handling as staged programming) |
Date: | 2025-04-06 17:33:47 |
Message-ID: | 2965818.1743960827@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Chapman Flack <jcflack(at)acm(dot)org> writes:
> To wit, given a query like
> SELECT hello(n), hello(x)
> FROM (VALUES
> (1::int4, 1.0::float4),
> (2, 2.0 ),
> (3, 3.0 )) AS t(n,x);
> the core code allocates one FmgrInfo for each of the two uses.
Yeah, there's no attempt to merge FmgrInfos across call sites
within a query. It's typical to use fn_extra to point to dynamic
state for a call, so that any such merging could break things.
> I wonder, though, if there might be code in the wild, or even in corners
> of the core I haven't looked in, where FmgrInfo structs aren't being used
> that way, and could get reused for successive calls of one routine but
> with, say, different nargs or argument types. That would seem odd but
> I don't see that the documentation ever came right out and said not to.
The only case I'm aware of that might require some thought is that the
relcache caches FmgrInfo structs for the opclass support functions for
each column of an index. That seems like it's close enough to being
just as specialized as a query callsite, but maybe not?
A downside of relying entirely on fn_extra is that you don't get to
amortize the specialization work across queries, even though it's
probably pretty repetitive. You might be interested in this recent
commit:
which formalizes some caching rules that plpgsql has used for
a long time, and extends the rules to support SQL-language
functions (which need to specialize on output rowtype as well
as what plpgsql has traditionally considered). Maybe you'd be
interested in using funccache.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Álvaro Herrera | 2025-04-06 17:34:51 | Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote |
Previous Message | Tom Lane | 2025-04-06 17:21:53 | Re: getting "shell command argument contains a newline or carriage return:" error with pg_dumpall when db name have new line in double quote |