On 11/14/26 02:29, [email protected] wrote:
Compared with master:

                     no name cache          cache + check
                     per call   query       per call   query
'int4'              +277 ns    2.9x        +3.5 ns    +2.4%
'varchar(10)'       +509 ns    4.4x        +4.2 ns    +2.7%
'numeric(7,4)'      +649 ns    4.9x        +4.3 ns    +2.6%
domain in public    +302 ns    3.0x        +3.5 ns    +2.2%
PL/pgSQL variable   +270 ns    3.8x        +7.7 ns    +8.4%

On master, pg_input_is_valid() costs 23 to 62 ns per call in these
queries.

With "cache + check", the function gives the same answers as if
nothing were cached when a type is dropped and recreated under the
same name, or search_path changes between calls, including between
two FETCHes from the same cursor. If a type is dropped without being
recreated, it now reports "type ... does not exist" instead of
"cache lookup failed for type".

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?

 > If this function had been added now I
 > personally would have preferred the signature to be:
 >
 > pg_input_is_valid(text, regtype)

regtypein() parses the typmod but returns only the OID, so a regtype
argument loses the typmod. The documentation example
pg_input_is_valid('1234.567', 'numeric(7,4)') returns false, but with
a regtype argument it would lose the (7,4) and return true.

Good point.

> Do we have similar optimizations for other functions which take a type name?

No. Other functions that take a type name as text, such as
to_regtype() and regtypein(), parse it on every call. I did not find
another function that caches it.

Yeah, I did not find one either.

--
Andreas Karlsson
Percona



Reply via email to