Re: [PATCH] pg_input_is_valid() reuses the first type name inside a PL/pgSQL loop

From: Xnerv Wang <xnervwang(at)gmail(dot)com>
To: Andreas Karlsson <andreas(at)proxel(dot)se>
Cc: 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:28:51
Message-ID: CAFEh72CdFu0GLiJCUiUC7VS8dSh-s75aSshm6a8rmrBv3-3nyw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Thanks,
Xnerv Wang
Amazon Web Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-11-25 19:30:52 Re: passwordcheck: Make the user name check case-insensitive
Previous Message Tom Lane 2026-11-25 19:24:38 Re: passwordcheck: Make the user name check case-insensitive