Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4bf3c9

Browse files
committed
Expose an API for calculating catcache hash values.
Now that cache invalidation callbacks get only a hash value, and not atuple TID (per commits632ae68 andb5282aa), the only way they can restrictwhat they invalidate is to know what the hash values mean. setrefs.c wasdoing this via a hard-wired assumption but that seems pretty grotty, andit'll only get worse as more cases come up. So let's expose a calculationfunction that takes the same parameters as SearchSysCache. Per complaintfrom Marko Kreen.
1 parente685a8e commitd4bf3c9

File tree

5 files changed

+83
-7
lines changed

5 files changed

+83
-7
lines changed

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
#include"postgres.h"
1717

18-
#include"access/hash.h"
1918
#include"access/transam.h"
2019
#include"catalog/pg_type.h"
2120
#include"nodes/makefuncs.h"
@@ -1830,14 +1829,11 @@ record_plan_function_dependency(PlannerInfo *root, Oid funcid)
18301829
/*
18311830
* It would work to use any syscache on pg_proc, but the easiest is
18321831
* PROCOID since we already have the function's OID at hand. Note
1833-
* that plancache.c knows we use PROCOID. Also, we're perhaps
1834-
* assuming more than we should about how CatalogCacheComputeHashValue
1835-
* computes hash values...
1832+
* that plancache.c knows we use PROCOID.
18361833
*/
18371834
inval_item->cacheId=PROCOID;
1838-
inval_item->hashValue=
1839-
DatumGetUInt32(DirectFunctionCall1(hashoid,
1840-
ObjectIdGetDatum(funcid)));
1835+
inval_item->hashValue=GetSysCacheHashValue1(PROCOID,
1836+
ObjectIdGetDatum(funcid));
18411837

18421838
root->glob->invalItems=lappend(root->glob->invalItems,inval_item);
18431839
}

‎src/backend/utils/cache/catcache.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,46 @@ ReleaseCatCache(HeapTuple tuple)
12811281
}
12821282

12831283

1284+
/*
1285+
*GetCatCacheHashValue
1286+
*
1287+
*Compute the hash value for a given set of search keys.
1288+
*
1289+
* The reason for exposing this as part of the API is that the hash value is
1290+
* exposed in cache invalidation operations, so there are places outside the
1291+
* catcache code that need to be able to compute the hash values.
1292+
*/
1293+
uint32
1294+
GetCatCacheHashValue(CatCache*cache,
1295+
Datumv1,
1296+
Datumv2,
1297+
Datumv3,
1298+
Datumv4)
1299+
{
1300+
ScanKeyDatacur_skey[CATCACHE_MAXKEYS];
1301+
1302+
/*
1303+
* one-time startup overhead for each cache
1304+
*/
1305+
if (cache->cc_tupdesc==NULL)
1306+
CatalogCacheInitializeCache(cache);
1307+
1308+
/*
1309+
* initialize the search key information
1310+
*/
1311+
memcpy(cur_skey,cache->cc_skey,sizeof(cur_skey));
1312+
cur_skey[0].sk_argument=v1;
1313+
cur_skey[1].sk_argument=v2;
1314+
cur_skey[2].sk_argument=v3;
1315+
cur_skey[3].sk_argument=v4;
1316+
1317+
/*
1318+
* calculate the hash value
1319+
*/
1320+
returnCatalogCacheComputeHashValue(cache,cache->cc_nkeys,cur_skey);
1321+
}
1322+
1323+
12841324
/*
12851325
*SearchCatCacheList
12861326
*

‎src/backend/utils/cache/syscache.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,30 @@ SysCacheGetAttr(int cacheId, HeapTuple tup,
10501050
isNull);
10511051
}
10521052

1053+
/*
1054+
* GetSysCacheHashValue
1055+
*
1056+
* Get the hash value that would be used for a tuple in the specified cache
1057+
* with the given search keys.
1058+
*
1059+
* The reason for exposing this as part of the API is that the hash value is
1060+
* exposed in cache invalidation operations, so there are places outside the
1061+
* catcache code that need to be able to compute the hash values.
1062+
*/
1063+
uint32
1064+
GetSysCacheHashValue(intcacheId,
1065+
Datumkey1,
1066+
Datumkey2,
1067+
Datumkey3,
1068+
Datumkey4)
1069+
{
1070+
if (cacheId<0||cacheId >=SysCacheSize||
1071+
!PointerIsValid(SysCache[cacheId]))
1072+
elog(ERROR,"invalid cache ID: %d",cacheId);
1073+
1074+
returnGetCatCacheHashValue(SysCache[cacheId],key1,key2,key3,key4);
1075+
}
1076+
10531077
/*
10541078
* List-search interface
10551079
*/

‎src/include/utils/catcache.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ extern HeapTuple SearchCatCache(CatCache *cache,
174174
Datumv3,Datumv4);
175175
externvoidReleaseCatCache(HeapTupletuple);
176176

177+
externuint32GetCatCacheHashValue(CatCache*cache,
178+
Datumv1,Datumv2,
179+
Datumv3,Datumv4);
180+
177181
externCatCList*SearchCatCacheList(CatCache*cache,intnkeys,
178182
Datumv1,Datumv2,
179183
Datumv3,Datumv4);

‎src/include/utils/syscache.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ extern bool SearchSysCacheExistsAttName(Oid relid, const char *attname);
113113
externDatumSysCacheGetAttr(intcacheId,HeapTupletup,
114114
AttrNumberattributeNumber,bool*isNull);
115115

116+
externuint32GetSysCacheHashValue(intcacheId,
117+
Datumkey1,Datumkey2,Datumkey3,Datumkey4);
118+
116119
/* list-search interface. Users of this must import catcache.h too */
117120
externstructcatclist*SearchSysCacheList(intcacheId,intnkeys,
118121
Datumkey1,Datumkey2,Datumkey3,Datumkey4);
@@ -158,6 +161,15 @@ extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
158161
#defineGetSysCacheOid4(cacheId,key1,key2,key3,key4) \
159162
GetSysCacheOid(cacheId, key1, key2, key3, key4)
160163

164+
#defineGetSysCacheHashValue1(cacheId,key1) \
165+
GetSysCacheHashValue(cacheId, key1, 0, 0, 0)
166+
#defineGetSysCacheHashValue2(cacheId,key1,key2) \
167+
GetSysCacheHashValue(cacheId, key1, key2, 0, 0)
168+
#defineGetSysCacheHashValue3(cacheId,key1,key2,key3) \
169+
GetSysCacheHashValue(cacheId, key1, key2, key3, 0)
170+
#defineGetSysCacheHashValue4(cacheId,key1,key2,key3,key4) \
171+
GetSysCacheHashValue(cacheId, key1, key2, key3, key4)
172+
161173
#defineSearchSysCacheList1(cacheId,key1) \
162174
SearchSysCacheList(cacheId, 1, key1, 0, 0, 0)
163175
#defineSearchSysCacheList2(cacheId,key1,key2) \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp