On Tue, Nov 24, 2026 at 8:38 PM Andreas Karlsson <[email protected]> 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
