[COMMITTERS] pgsql: Avoid searching for the target catcache inCatalogCacheIdInvalid - Mailing list pgsql-committers

From Tom Lane
Subject [COMMITTERS] pgsql: Avoid searching for the target catcache inCatalogCacheIdInvalid
Date
Msg-id E1d9Isi-0007wq-1n@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid searching for the target catcache in CatalogCacheIdInvalidate.

A test case provided by Mathieu Fenniak shows that the initial search for
the target catcache in CatalogCacheIdInvalidate consumes a very significant
amount of overhead in cases where cache invalidation is triggered but has
little useful work to do.  There is no good reason for that search to exist
at all, as the index array maintained by syscache.c allows direct lookup of
the catcache from its ID.  We just need a frontend function in syscache.c,
matching the division of labor for most other cache-accessing operations.

While there's more that can be done in this area, this patch alone reduces
the runtime of Mathieu's example by 2X.  We can hope that it offers some
useful benefit in other cases too, although usually cache invalidation
overhead is not such a striking fraction of the total runtime.

Back-patch to 9.4 where logical decoding was introduced.  It might be
worth going further back, but presently the only case we know of where
cache invalidation is really a significant burden is in logical decoding.
Also, older branches have fewer catcaches, reducing the possible benefit.

(Note: although this nominally changes catcache's API, we have always
documented CatalogCacheIdInvalidate as a private function, so I would
have little sympathy for an external module calling it directly.  So
backpatching should be fine.)

Discussion: https://postgr.es/m/CAHoiPjzea6N0zuCi=+f9v_j94nfsy6y8SU7-=bp4=7qw6_i=Rg@mail.gmail.com

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3569a9a73e6aa7d5b813115cc0a28969592bdc1f

Modified Files
--------------
src/backend/utils/cache/catcache.c | 92 ++++++++++++++++----------------------
src/backend/utils/cache/inval.c    |  2 +-
src/backend/utils/cache/syscache.c | 21 +++++++++
src/include/utils/catcache.h       |  2 +-
src/include/utils/syscache.h       |  2 +
5 files changed, 64 insertions(+), 55 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: [COMMITTERS] pgsql: Fix dependencies for extended statistics objects.
Next
From: Alvaro Herrera
Date:
Subject: [COMMITTERS] pgsql: getObjectDescription: support extended statistics