Skip to content

Commit 80dab5b

Browse files
committed
A catalog cache that never caches isn't much of a cache :-(. Mea culpa.
Thanks to Brian Hirt for pointing out the performance lossage.
1 parent 48437f5 commit 80dab5b

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/backend/utils/cache/catcache.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.72 2000/11/16 22:30:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.73 2000/11/24 04:16:12 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -258,8 +258,8 @@ CatalogCacheInitializeCache(CatCache *cache)
258258
&cache->cc_skey[i].sk_func);
259259
cache->cc_skey[i].sk_nargs = cache->cc_skey[i].sk_func.fn_nargs;
260260

261-
/* Initialize sk_attno suitably for index scans */
262-
cache->cc_skey[i].sk_attno = i+1;
261+
/* Initialize sk_attno suitably for HeapKeyTest() and heap scans */
262+
cache->cc_skey[i].sk_attno = cache->cc_key[i];
263263

264264
CACHE4_elog(DEBUG, "CatalogCacheInit %s %d %p",
265265
cache->cc_relname,
@@ -664,8 +664,8 @@ InitCatCache(int id,
664664

665665
/* ----------------
666666
* initialize the cache's relation information for the relation
667-
* corresponding to this cache and initialize some of the the new
668-
* cache's other internal fields.
667+
* corresponding to this cache, and initialize some of the new
668+
* cache's other internal fields. But don't open the relation yet.
669669
* ----------------
670670
*/
671671
cp->cc_relname = relname;
@@ -885,10 +885,20 @@ SearchCatCache(CatCache *cache,
885885
RetrieveIndexResult indexRes;
886886
HeapTupleData tuple;
887887
Buffer buffer;
888+
int i;
888889

889890
CACHE2_elog(DEBUG, "SearchCatCache(%s): performing index scan",
890891
cache->cc_relname);
891892

893+
/*
894+
* For an index scan, sk_attno has to be set to the index attribute
895+
* number(s), not the heap attribute numbers. We assume that the
896+
* index corresponds exactly to the cache keys (or its first N
897+
* keys do, anyway).
898+
*/
899+
for (i = 0; i < cache->cc_nkeys; ++i)
900+
cur_skey[i].sk_attno = i+1;
901+
892902
idesc = index_openr(cache->cc_indname);
893903
isd = index_beginscan(idesc, false, cache->cc_nkeys, cur_skey);
894904
tuple.t_datamcxt = CurrentMemoryContext;
@@ -915,18 +925,10 @@ SearchCatCache(CatCache *cache,
915925
else
916926
{
917927
HeapScanDesc sd;
918-
int i;
919928

920929
CACHE2_elog(DEBUG, "SearchCatCache(%s): performing heap scan",
921930
cache->cc_relname);
922931

923-
/*
924-
* For a heap scan, sk_attno has to be set to the heap attribute
925-
* number(s), not the index attribute numbers.
926-
*/
927-
for (i = 0; i < cache->cc_nkeys; ++i)
928-
cur_skey[i].sk_attno = cache->cc_key[i];
929-
930932
sd = heap_beginscan(relation, 0, SnapshotNow,
931933
cache->cc_nkeys, cur_skey);
932934

src/include/utils/catcache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $Id: catcache.h,v 1.28 2000/11/16 22:30:49 tgl Exp $
16+
* $Id: catcache.h,v 1.29 2000/11/24 04:16:11 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -70,7 +70,7 @@ typedef struct catcache
7070
short cc_nkeys; /* number of keys (1..4) */
7171
short cc_key[4]; /* AttrNumber of each key */
7272
PGFunction cc_hashfunc[4]; /* hash function to use for each key */
73-
ScanKeyData cc_skey[4]; /* precomputed key info for indexscans */
73+
ScanKeyData cc_skey[4]; /* precomputed key info for heap scans */
7474
Dllist cc_lrulist; /* overall LRU list, most recent first */
7575
Dllist cc_cache[NCCBUCK]; /* hash buckets */
7676
} CatCache;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy