Cache the results of format_type() queries in pg_dump.
authorTom Lane <[email protected]>
Tue, 31 Aug 2021 17:53:33 +0000 (13:53 -0400)
committerTom Lane <[email protected]>
Tue, 31 Aug 2021 17:53:51 +0000 (13:53 -0400)
commit0e7bdc722c65045d85161c6ae0125743ae93d185
tree48264d988ec4f6e39f2a7e2710647ac75312f75c
parent6963e723f1dde295397a6a31b36775da7de8357b
Cache the results of format_type() queries in pg_dump.

There's long been a "TODO: there might be some value in caching
the results" annotation on pg_dump's getFormattedTypeName function;
but we hadn't gotten around to checking what it was costing us to
repetitively look up type names.  It turns out that when dumping the
current regression database, about 10% of the total number of queries
issued are duplicative format_type() queries.  However, Hubert Depesz
Lubaczewski reported a not-unusual case where these account for over
half of the queries issued by pg_dump.  Individually these queries
aren't expensive, but when network lag is a factor, they add up to a
problem.  We can very easily add some caching to getFormattedTypeName
to solve it.

Since this is such a simple fix and can have a visible performance
benefit, back-patch to all supported branches.

Discussion: https://postgr.es/m/20210826084430[email protected]
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h