]> granicus.if.org Git - postgresql/commitdiff
Save a few bytes by removing useless last argument to SearchCatCacheList.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 29 Jan 2018 20:13:07 +0000 (15:13 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 29 Jan 2018 20:13:17 +0000 (15:13 -0500)
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 e26c539e9, 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

src/backend/utils/cache/catcache.c
src/backend/utils/cache/syscache.c
src/include/utils/catcache.h
src/include/utils/syscache.h

index 8a0a42ce712ca3c6f29549fcd526b6387ac298c4..5ddbf6eab10d03d83120774b743613dc23cc787f 100644 (file)
@@ -1512,6 +1512,11 @@ GetCatCacheHashValue(CatCache *cache,
  *             Generate a list of all tuples matching a partial key (that is,
  *             a key specifying just the first K of the cache's N key columns).
  *
+ *             It doesn't make any sense to specify all of the cache's key columns
+ *             here: since the key is unique, there could be at most one match, so
+ *             you ought to use SearchCatCache() instead.  Hence this function takes
+ *             one less Datum argument than SearchCatCache() does.
+ *
  *             The caller must not modify the list object or the pointed-to tuples,
  *             and must call ReleaseCatCacheList() when done with the list.
  */
@@ -1520,9 +1525,9 @@ SearchCatCacheList(CatCache *cache,
                                   int nkeys,
                                   Datum v1,
                                   Datum v2,
-                                  Datum v3,
-                                  Datum v4)
+                                  Datum v3)
 {
+       Datum           v4 = 0;                 /* dummy last-column value */
        Datum           arguments[CATCACHE_MAXKEYS];
        uint32          lHashValue;
        dlist_iter      iter;
index 041cd53a30078dd2772298eaf9f42948dc59a1e8..2b381782a325e484933f2520775c88bbf402cb57 100644 (file)
@@ -1418,14 +1418,14 @@ GetSysCacheHashValue(int cacheId,
  */
 struct catclist *
 SearchSysCacheList(int cacheId, int nkeys,
-                                  Datum key1, Datum key2, Datum key3, Datum key4)
+                                  Datum key1, Datum key2, Datum key3)
 {
        if (cacheId < 0 || cacheId >= SysCacheSize ||
                !PointerIsValid(SysCache[cacheId]))
                elog(ERROR, "invalid cache ID: %d", cacheId);
 
        return SearchCatCacheList(SysCache[cacheId], nkeys,
-                                                         key1, key2, key3, key4);
+                                                         key1, key2, key3);
 }
 
 /*
index 39d4876169194111afcad4ebb35991e7c5caf3a3..7b22f9c7bc54f4a4e10c5108a6990d51f438eb37 100644 (file)
@@ -214,7 +214,7 @@ extern uint32 GetCatCacheHashValue(CatCache *cache,
 
 extern CatCList *SearchCatCacheList(CatCache *cache, int nkeys,
                                   Datum v1, Datum v2,
-                                  Datum v3, Datum v4);
+                                  Datum v3);
 extern void ReleaseCatCacheList(CatCList *list);
 
 extern void ResetCatalogCaches(void);
index 55d573c687f5c53a2deb734138cc8c61a307783e..4f333586ee99a721effb3897c6e52c800a033384 100644 (file)
@@ -157,7 +157,7 @@ extern uint32 GetSysCacheHashValue(int cacheId,
 /* list-search interface.  Users of this must import catcache.h too */
 struct catclist;
 extern struct catclist *SearchSysCacheList(int cacheId, int nkeys,
-                                  Datum key1, Datum key2, Datum key3, Datum key4);
+                                  Datum key1, Datum key2, Datum key3);
 
 extern void SysCacheInvalidate(int cacheId, uint32 hashValue);
 
@@ -207,13 +207,11 @@ extern bool RelationSupportsSysCache(Oid relid);
        GetSysCacheHashValue(cacheId, key1, key2, key3, key4)
 
 #define SearchSysCacheList1(cacheId, key1) \
-       SearchSysCacheList(cacheId, 1, key1, 0, 0, 0)
+       SearchSysCacheList(cacheId, 1, key1, 0, 0)
 #define SearchSysCacheList2(cacheId, key1, key2) \
-       SearchSysCacheList(cacheId, 2, key1, key2, 0, 0)
+       SearchSysCacheList(cacheId, 2, key1, key2, 0)
 #define SearchSysCacheList3(cacheId, key1, key2, key3) \
-       SearchSysCacheList(cacheId, 3, key1, key2, key3, 0)
-#define SearchSysCacheList4(cacheId, key1, key2, key3, key4) \
-       SearchSysCacheList(cacheId, 4, key1, key2, key3, key4)
+       SearchSysCacheList(cacheId, 3, key1, key2, key3)
 
 #define ReleaseSysCacheList(x) ReleaseCatCacheList(x)