A catalog cache that never caches isn't much of a cache :-(. Mea culpa.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 24 Nov 2000 04:16:12 +0000 (04:16 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 24 Nov 2000 04:16:12 +0000 (04:16 +0000)
Thanks to Brian Hirt for pointing out the performance lossage.

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

index 839801c455978fb75f24970acaeee6d773010271..172f6740642559082e3bbb761c5b354f9a9bdeb6 100644 (file)
@@ -258,8 +258,8 @@ CatalogCacheInitializeCache(CatCache *cache)
                                  &cache->cc_skey[i].sk_func);
                cache->cc_skey[i].sk_nargs = cache->cc_skey[i].sk_func.fn_nargs;
 
-               /* Initialize sk_attno suitably for index scans */
-               cache->cc_skey[i].sk_attno = i+1;
+               /* Initialize sk_attno suitably for HeapKeyTest() and heap scans */
+               cache->cc_skey[i].sk_attno = cache->cc_key[i];
 
                CACHE4_elog(DEBUG, "CatalogCacheInit %s %d %p",
                                        cache->cc_relname,
@@ -664,8 +664,8 @@ InitCatCache(int id,
 
        /* ----------------
         *      initialize the cache's relation information for the relation
-        *      corresponding to this cache and initialize some of the the new
-        *      cache's other internal fields.
+        *      corresponding to this cache, and initialize some of the new
+        *      cache's other internal fields.  But don't open the relation yet.
         * ----------------
         */
        cp->cc_relname = relname;
@@ -885,10 +885,20 @@ SearchCatCache(CatCache *cache,
                RetrieveIndexResult indexRes;
                HeapTupleData tuple;
                Buffer          buffer;
+               int                     i;
 
                CACHE2_elog(DEBUG, "SearchCatCache(%s): performing index scan",
                                        cache->cc_relname);
 
+               /*
+                * For an index scan, sk_attno has to be set to the index attribute
+                * number(s), not the heap attribute numbers.  We assume that the
+                * index corresponds exactly to the cache keys (or its first N
+                * keys do, anyway).
+                */
+               for (i = 0; i < cache->cc_nkeys; ++i)
+                       cur_skey[i].sk_attno = i+1;
+
                idesc = index_openr(cache->cc_indname);
                isd = index_beginscan(idesc, false, cache->cc_nkeys, cur_skey);
                tuple.t_datamcxt = CurrentMemoryContext;
@@ -915,18 +925,10 @@ SearchCatCache(CatCache *cache,
        else
        {
                HeapScanDesc sd;
-               int                     i;
 
                CACHE2_elog(DEBUG, "SearchCatCache(%s): performing heap scan",
                                        cache->cc_relname);
 
-               /*
-                * For a heap scan, sk_attno has to be set to the heap attribute
-                * number(s), not the index attribute numbers.
-                */
-               for (i = 0; i < cache->cc_nkeys; ++i)
-                       cur_skey[i].sk_attno = cache->cc_key[i];
-
                sd = heap_beginscan(relation, 0, SnapshotNow,
                                                        cache->cc_nkeys, cur_skey);
 
index 8643f9bacf6cca4e8f75b12818c7d8af16840040..8825753b6c026706232d8f31d084e661513ef778 100644 (file)
@@ -70,7 +70,7 @@ typedef struct catcache
        short           cc_nkeys;               /* number of keys (1..4) */
        short           cc_key[4];              /* AttrNumber of each key */
        PGFunction      cc_hashfunc[4]; /* hash function to use for each key */
-       ScanKeyData cc_skey[4];         /* precomputed key info for indexscans */
+       ScanKeyData cc_skey[4];         /* precomputed key info for heap scans */
        Dllist          cc_lrulist;             /* overall LRU list, most recent first */
        Dllist          cc_cache[NCCBUCK]; /* hash buckets */
 } CatCache;