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 3d8e7d80ba8cff72a59ec59cd845b8ca0153faab..3e1c428a532728d68ebd5d439951da0ebe8d550e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.72 2000/11/16 22:30:33 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.73 2000/11/24 04:16:12 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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 ed78284a47890ade71ef0466b346779bb0ea4371..70c988ca185b40c3b2cc341f8cae0fddc6a28c82 100644 (file)
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: catcache.h,v 1.28 2000/11/16 22:30:49 tgl Exp $
+ * $Id: catcache.h,v 1.29 2000/11/24 04:16:11 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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;