mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
Remove the limit on the number of entries allowed in catcaches, and
remove the infrastructure needed to enforce the limit, ie, the global LRU list of cache entries. On small-to-middling databases this wins because maintaining the LRU list is a waste of time. On large databases this wins because it's better to keep more cache entries (we assume such users can afford to use some more per-backend memory than was contemplated in the Berkeley-era catcache design). This provides a noticeable improvement in the speed of psql \d on a 10000-table database, though it doesn't make it instantaneous. While at it, use per-catcache settings for the number of hash buckets per catcache, rather than the former one-size-fits-all value. It's a bit silly to be using the same number of hash buckets for, eg, pg_am and pg_attribute. The specific values I used might need some tuning, but they seem to be in the right ballpark based on CATCACHE_STATS results from the standard regression tests.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/utils/catcache.h,v 1.58 2006/03/05 15:59:07 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/utils/catcache.h,v 1.59 2006/06/15 02:08:09 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -60,7 +60,6 @@ typedef struct catcache
|
||||
* searches, each of which will result in loading a negative entry
|
||||
*/
|
||||
long cc_invals; /* # of entries invalidated from cache */
|
||||
long cc_discards; /* # of entries discarded due to overflow */
|
||||
long cc_lsearches; /* total # list-searches */
|
||||
long cc_lhits; /* # of matches against existing lists */
|
||||
#endif
|
||||
@@ -75,11 +74,10 @@ typedef struct catctup
|
||||
CatCache *my_cache; /* link to owning catcache */
|
||||
|
||||
/*
|
||||
* Each tuple in a cache is a member of two Dllists: one lists all the
|
||||
* elements in all the caches in LRU order, and the other lists just the
|
||||
* elements in one hashbucket of one cache, also in LRU order.
|
||||
* Each tuple in a cache is a member of a Dllist that stores the elements
|
||||
* of its hash bucket. We keep each Dllist in LRU order to speed repeated
|
||||
* lookups.
|
||||
*/
|
||||
Dlelem lrulist_elem; /* list member of global LRU list */
|
||||
Dlelem cache_elem; /* list member of per-bucket list */
|
||||
|
||||
/*
|
||||
@@ -125,9 +123,8 @@ typedef struct catclist
|
||||
* table rows satisfying the partial key. (Note: none of these will be
|
||||
* negative cache entries.)
|
||||
*
|
||||
* A CatCList is only a member of a per-cache list; we do not do separate
|
||||
* LRU management for CatCLists. See CatalogCacheCleanup() for the
|
||||
* details of the management algorithm.
|
||||
* A CatCList is only a member of a per-cache list; we do not currently
|
||||
* divide them into hash buckets.
|
||||
*
|
||||
* A list marked "dead" must not be returned by subsequent searches.
|
||||
* However, it won't be physically deleted from the cache until its
|
||||
@@ -143,7 +140,6 @@ typedef struct catclist
|
||||
int refcount; /* number of active references */
|
||||
bool dead; /* dead but not yet removed? */
|
||||
bool ordered; /* members listed in index order? */
|
||||
bool touched; /* used since last CatalogCacheCleanup? */
|
||||
short nkeys; /* number of lookup keys specified */
|
||||
uint32 hash_value; /* hash value for lookup keys */
|
||||
HeapTupleData tuple; /* header for tuple holding keys */
|
||||
@@ -156,8 +152,6 @@ typedef struct catcacheheader
|
||||
{
|
||||
CatCache *ch_caches; /* head of list of CatCache structs */
|
||||
int ch_ntup; /* # of tuples in all caches */
|
||||
int ch_maxtup; /* max # of tuples allowed (LRU) */
|
||||
Dllist ch_lrulist; /* overall LRU list, most recent first */
|
||||
} CatCacheHeader;
|
||||
|
||||
|
||||
@@ -169,7 +163,8 @@ extern void AtEOXact_CatCache(bool isCommit);
|
||||
|
||||
extern CatCache *InitCatCache(int id, Oid reloid, Oid indexoid,
|
||||
int reloidattr,
|
||||
int nkeys, const int *key);
|
||||
int nkeys, const int *key,
|
||||
int nbuckets);
|
||||
extern void InitCatCachePhase2(CatCache *cache);
|
||||
|
||||
extern HeapTuple SearchCatCache(CatCache *cache,
|
||||
|
||||
Reference in New Issue
Block a user