Skip to content

Commit 97d4445

Browse files
committed
Save a few bytes by removing useless last argument to SearchCatCacheList.
There's never any value in giving a fully specified cache key to SearchCatCacheList: you might as well call SearchCatCache instead, since there could be only one match. So the maximum useful number of key arguments is one less than the supported number of key columns. We might as well remove the useless extra argument and save some few bytes per call site, as well as a cycle or so per call. I believe the reason it was coded like this is that originally, callers had to write out all the dummy arguments in each call, and so it seemed less confusing if SearchCatCache and SearchCatCacheList took the same number of key arguments. But since commit e26c539, callers only write their live arguments explicitly, making that a non-factor; and there's surely been enough time for third-party modules to adapt to that coding style. So this is only an ABI break not an API break for callers. Per discussion with Oliver Ford, this might also make it less confusing how to use SearchCatCacheList correctly. Discussion: https://postgr.es/m/27788.1517069693@sss.pgh.pa.us
1 parent fc96c69 commit 97d4445

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/backend/utils/cache/catcache.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,11 @@ GetCatCacheHashValue(CatCache *cache,
15121512
* Generate a list of all tuples matching a partial key (that is,
15131513
* a key specifying just the first K of the cache's N key columns).
15141514
*
1515+
* It doesn't make any sense to specify all of the cache's key columns
1516+
* here: since the key is unique, there could be at most one match, so
1517+
* you ought to use SearchCatCache() instead. Hence this function takes
1518+
* one less Datum argument than SearchCatCache() does.
1519+
*
15151520
* The caller must not modify the list object or the pointed-to tuples,
15161521
* and must call ReleaseCatCacheList() when done with the list.
15171522
*/
@@ -1520,9 +1525,9 @@ SearchCatCacheList(CatCache *cache,
15201525
int nkeys,
15211526
Datum v1,
15221527
Datum v2,
1523-
Datum v3,
1524-
Datum v4)
1528+
Datum v3)
15251529
{
1530+
Datum v4 = 0; /* dummy last-column value */
15261531
Datum arguments[CATCACHE_MAXKEYS];
15271532
uint32 lHashValue;
15281533
dlist_iter iter;

src/backend/utils/cache/syscache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,14 +1418,14 @@ GetSysCacheHashValue(int cacheId,
14181418
*/
14191419
struct catclist *
14201420
SearchSysCacheList(int cacheId, int nkeys,
1421-
Datum key1, Datum key2, Datum key3, Datum key4)
1421+
Datum key1, Datum key2, Datum key3)
14221422
{
14231423
if (cacheId < 0 || cacheId >= SysCacheSize ||
14241424
!PointerIsValid(SysCache[cacheId]))
14251425
elog(ERROR, "invalid cache ID: %d", cacheId);
14261426

14271427
return SearchCatCacheList(SysCache[cacheId], nkeys,
1428-
key1, key2, key3, key4);
1428+
key1, key2, key3);
14291429
}
14301430

14311431
/*

src/include/utils/catcache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ extern uint32 GetCatCacheHashValue(CatCache *cache,
214214

215215
extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys,
216216
Datum v1, Datum v2,
217-
Datum v3, Datum v4);
217+
Datum v3);
218218
extern void ReleaseCatCacheList(CatCList *list);
219219

220220
extern void ResetCatalogCaches(void);

src/include/utils/syscache.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ extern uint32 GetSysCacheHashValue(int cacheId,
157157
/* list-search interface. Users of this must import catcache.h too */
158158
struct catclist;
159159
extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
160-
Datum key1, Datum key2, Datum key3, Datum key4);
160+
Datum key1, Datum key2, Datum key3);
161161

162162
extern void SysCacheInvalidate(int cacheId, uint32 hashValue);
163163

@@ -207,13 +207,11 @@ extern bool RelationSupportsSysCache(Oid relid);
207207
GetSysCacheHashValue(cacheId, key1, key2, key3, key4)
208208

209209
#define SearchSysCacheList1(cacheId, key1) \
210-
SearchSysCacheList(cacheId, 1, key1, 0, 0, 0)
210+
SearchSysCacheList(cacheId, 1, key1, 0, 0)
211211
#define SearchSysCacheList2(cacheId, key1, key2) \
212-
SearchSysCacheList(cacheId, 2, key1, key2, 0, 0)
212+
SearchSysCacheList(cacheId, 2, key1, key2, 0)
213213
#define SearchSysCacheList3(cacheId, key1, key2, key3) \
214-
SearchSysCacheList(cacheId, 3, key1, key2, key3, 0)
215-
#define SearchSysCacheList4(cacheId, key1, key2, key3, key4) \
216-
SearchSysCacheList(cacheId, 4, key1, key2, key3, key4)
214+
SearchSysCacheList(cacheId, 3, key1, key2, key3)
217215

218216
#define ReleaseSysCacheList(x) ReleaseCatCacheList(x)
219217

0 commit comments

Comments
 (0)