mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Expose an API for calculating catcache hash values.
Now that cache invalidation callbacks get only a hash value, and not a tuple TID (per commits632ae6829fandb5282aa893), the only way they can restrict what they invalidate is to know what the hash values mean. setrefs.c was doing this via a hard-wired assumption but that seems pretty grotty, and it'll only get worse as more cases come up. So let's expose a calculation function that takes the same parameters as SearchSysCache. Per complaint from Marko Kreen.
This commit is contained in:
40
src/backend/utils/cache/catcache.c
vendored
40
src/backend/utils/cache/catcache.c
vendored
@@ -1281,6 +1281,46 @@ ReleaseCatCache(HeapTuple tuple)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* GetCatCacheHashValue
|
||||
*
|
||||
* Compute the hash value for a given set of search keys.
|
||||
*
|
||||
* The reason for exposing this as part of the API is that the hash value is
|
||||
* exposed in cache invalidation operations, so there are places outside the
|
||||
* catcache code that need to be able to compute the hash values.
|
||||
*/
|
||||
uint32
|
||||
GetCatCacheHashValue(CatCache *cache,
|
||||
Datum v1,
|
||||
Datum v2,
|
||||
Datum v3,
|
||||
Datum v4)
|
||||
{
|
||||
ScanKeyData cur_skey[CATCACHE_MAXKEYS];
|
||||
|
||||
/*
|
||||
* one-time startup overhead for each cache
|
||||
*/
|
||||
if (cache->cc_tupdesc == NULL)
|
||||
CatalogCacheInitializeCache(cache);
|
||||
|
||||
/*
|
||||
* initialize the search key information
|
||||
*/
|
||||
memcpy(cur_skey, cache->cc_skey, sizeof(cur_skey));
|
||||
cur_skey[0].sk_argument = v1;
|
||||
cur_skey[1].sk_argument = v2;
|
||||
cur_skey[2].sk_argument = v3;
|
||||
cur_skey[3].sk_argument = v4;
|
||||
|
||||
/*
|
||||
* calculate the hash value
|
||||
*/
|
||||
return CatalogCacheComputeHashValue(cache, cache->cc_nkeys, cur_skey);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SearchCatCacheList
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user