| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | Xnerv Wang <xnervwang(at)gmail(dot)com> |
| Cc: | Andreas Karlsson <andreas(at)proxel(dot)se>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, John Naylor <johncnaylorls(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: [PATCH] pg_input_is_valid() reuses the first type name inside a PL/pgSQL loop |
| Date: | 2026-11-25 19:43:37 |
| Message-ID: | 1308129.1795635817@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Xnerv Wang <xnervwang(at)gmail(dot)com> writes:
> On Tue, Nov 24, 2026 at 8:38 PM Andreas Karlsson <andreas(at)proxel(dot)se> wrote:
>>> Keeping only the parse tree and looking up the name on every call
>>> costs 57 to 91 ns more per call than master, making the queries
>>> 1.4 to 1.6 times as long.
>> 1.5 times slower does not sound too horrible, how complex is that code
>> compared to cache + check?
> I measured two experimental versions in my last message; I didn't post
> either one. Against master in src/backend/utils/adt/misc.c, the
> parse-tree version adds about 50 lines and removes about 25; cache +
> check adds about 90 and removes about 10.
> The parse-tree version drops typname_constant and its
> get_fn_expr_arg_stable() check; it has no syscache callback or
> SearchPathMatcher. It keeps the type name string and two TypeName trees
> in a child memory context that it rebuilds when the string changes: one
> tree has the typmods and the lookup tree omits them. Each call looks up
> the type with LookupTypeNameOid() and recomputes the typmod and input
> function if the string or the resolved type OID changes.
> Cache + check registers a TYPENAMENSP syscache invalidation callback
> once per backend to bump a counter, and checks a SearchPathMatcher with
> SearchPathMatchesCurrentEnvironment(). As in v2, only stable non-Const
> arguments, such as the external Param PL/pgSQL uses for a variable,
> need reparsing when their string differs from the last one parsed. A
> change to the counter or search_path triggers reparsing for both Const
> and other stable arguments.
Let's just drop the attempt to skip executing parseTypeString().
I don't like the amount of complexity here, and I especially don't
like the precedent that any random function can register a syscache
callback. Those are not a free resource, and they consume cycles
behind your back too.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Masahiko Sawada | 2026-11-25 20:02:54 | Re: Fix LogStandbySnapshot() race during logical decoding activation |
| Previous Message | Ishjaap Singh | 2026-11-25 19:39:06 | Re: [PATCH] Fix interval input at minimum signed field values (BUG #19746) |