mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +03:00
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
This commit is contained in:
21
src/backend/utils/cache/syscache.c
vendored
21
src/backend/utils/cache/syscache.c
vendored
@ -1338,6 +1338,27 @@ SearchSysCacheList(int cacheId, int nkeys,
|
||||
key1, key2, key3, key4);
|
||||
}
|
||||
|
||||
/*
|
||||
* SysCacheInvalidate
|
||||
*
|
||||
* Invalidate entries in the specified cache, given a hash value.
|
||||
* See CatCacheInvalidate() for more info.
|
||||
*
|
||||
* This routine is only quasi-public: it should only be used by inval.c.
|
||||
*/
|
||||
void
|
||||
SysCacheInvalidate(int cacheId, uint32 hashValue)
|
||||
{
|
||||
if (cacheId < 0 || cacheId >= SysCacheSize)
|
||||
elog(ERROR, "invalid cache ID: %d", cacheId);
|
||||
|
||||
/* if this cache isn't initialized yet, no need to do anything */
|
||||
if (!PointerIsValid(SysCache[cacheId]))
|
||||
return;
|
||||
|
||||
CatCacheInvalidate(SysCache[cacheId], hashValue);
|
||||
}
|
||||
|
||||
/*
|
||||
* Certain relations that do not have system caches send snapshot invalidation
|
||||
* messages in lieu of catcache messages. This is for the benefit of
|
||||
|
Reference in New Issue
Block a user