diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-03-07 14:51:13 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-03-07 14:51:13 -0500 |
commit | d4bf3c9c94305e692349fb6fe0c67e483b72ae87 (patch) | |
tree | f8b6fb180e026683ad7a06ab723e98eb86986c9d /src/backend/utils/cache | |
parent | e685a8e6651b0e55996e6eba6917302607866793 (diff) | |
download | postgresql-d4bf3c9c94305e692349fb6fe0c67e483b72ae87.tar.gz postgresql-d4bf3c9c94305e692349fb6fe0c67e483b72ae87.zip |
Expose an API for calculating catcache hash values.
Now that cache invalidation callbacks get only a hash value, and not a
tuple TID (per commits 632ae6829f7abda34e15082c91d9dfb3fc0f298b and
b5282aa893e565b7844f8237462cb843438cdd5e), 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.
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r-- | src/backend/utils/cache/catcache.c | 40 | ||||
-rw-r--r-- | src/backend/utils/cache/syscache.c | 24 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c index acd0518748d..ea3daa599ca 100644 --- a/src/backend/utils/cache/catcache.c +++ b/src/backend/utils/cache/catcache.c @@ -1282,6 +1282,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 * * Generate a list of all tuples matching a partial key (that is, diff --git a/src/backend/utils/cache/syscache.c b/src/backend/utils/cache/syscache.c index 78ce0b881a5..c365ec7597a 100644 --- a/src/backend/utils/cache/syscache.c +++ b/src/backend/utils/cache/syscache.c @@ -1051,6 +1051,30 @@ SysCacheGetAttr(int cacheId, HeapTuple tup, } /* + * GetSysCacheHashValue + * + * Get the hash value that would be used for a tuple in the specified cache + * with the given 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 +GetSysCacheHashValue(int cacheId, + Datum key1, + Datum key2, + Datum key3, + Datum key4) +{ + if (cacheId < 0 || cacheId >= SysCacheSize || + !PointerIsValid(SysCache[cacheId])) + elog(ERROR, "invalid cache ID: %d", cacheId); + + return GetCatCacheHashValue(SysCache[cacheId], key1, key2, key3, key4); +} + +/* * List-search interface */ struct catclist * |