Further cleanup of catcache.c ilist changes.

Remove useless duplicate initialization of bucket headers, don't use a
dlist_mutable_iter in a performance-critical path that doesn't need it,
make some other cosmetic changes for consistency's sake.
This commit is contained in:
Tom Lane 2012-10-18 19:30:43 -04:00
parent dc5aeca168
commit 002191a1a3
1 changed files with 17 additions and 12 deletions

View File

@ -370,6 +370,7 @@ CatCacheRemoveCTup(CatCache *cache, CatCTup *ct)
return; /* nothing left to do */ return; /* nothing left to do */
} }
/* delink from linked list */
dlist_delete(&ct->cache_elem); dlist_delete(&ct->cache_elem);
/* free associated tuple data */ /* free associated tuple data */
@ -452,9 +453,9 @@ CatalogCacheIdInvalidate(int cacheId, uint32 hashValue)
*/ */
slist_foreach(cache_iter, &CacheHdr->ch_caches) slist_foreach(cache_iter, &CacheHdr->ch_caches)
{ {
CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur);
Index hashIndex; Index hashIndex;
dlist_mutable_iter iter; dlist_mutable_iter iter;
CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur);
if (cacheId != ccp->id) if (cacheId != ccp->id)
continue; continue;
@ -555,7 +556,7 @@ AtEOXact_CatCache(bool isCommit)
{ {
slist_iter cache_iter; slist_iter cache_iter;
slist_foreach(cache_iter, &(CacheHdr->ch_caches)) slist_foreach(cache_iter, &CacheHdr->ch_caches)
{ {
CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur); CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur);
dlist_iter iter; dlist_iter iter;
@ -682,7 +683,7 @@ CatalogCacheFlushCatalog(Oid catId)
CACHE2_elog(DEBUG2, "CatalogCacheFlushCatalog called for %u", catId); CACHE2_elog(DEBUG2, "CatalogCacheFlushCatalog called for %u", catId);
slist_foreach(iter, &(CacheHdr->ch_caches)) slist_foreach(iter, &CacheHdr->ch_caches)
{ {
CatCache *cache = slist_container(CatCache, cc_next, iter.cur); CatCache *cache = slist_container(CatCache, cc_next, iter.cur);
@ -770,8 +771,10 @@ InitCatCache(int id,
/* /*
* allocate a new cache structure * allocate a new cache structure
*
* Note: we rely on zeroing to initialize all the dlist headers correctly
*/ */
cp = (CatCache *) palloc0(sizeof(CatCache) + nbuckets * sizeof(dlist_node)); cp = (CatCache *) palloc0(sizeof(CatCache) + nbuckets * sizeof(dlist_head));
/* /*
* initialize the cache's relation information for the relation * initialize the cache's relation information for the relation
@ -790,9 +793,6 @@ InitCatCache(int id,
for (i = 0; i < nkeys; ++i) for (i = 0; i < nkeys; ++i)
cp->cc_key[i] = key[i]; cp->cc_key[i] = key[i];
dlist_init(&cp->cc_lists);
MemSet(&cp->cc_bucket, 0, nbuckets * sizeof(dlist_head));
/* /*
* new cache is initialized as far as we can go for now. print some * new cache is initialized as far as we can go for now. print some
* debugging information, if appropriate. * debugging information, if appropriate.
@ -1060,7 +1060,7 @@ SearchCatCache(CatCache *cache,
ScanKeyData cur_skey[CATCACHE_MAXKEYS]; ScanKeyData cur_skey[CATCACHE_MAXKEYS];
uint32 hashValue; uint32 hashValue;
Index hashIndex; Index hashIndex;
dlist_mutable_iter iter; dlist_iter iter;
dlist_head *bucket; dlist_head *bucket;
CatCTup *ct; CatCTup *ct;
Relation relation; Relation relation;
@ -1094,10 +1094,12 @@ SearchCatCache(CatCache *cache,
/* /*
* scan the hash bucket until we find a match or exhaust our tuples * scan the hash bucket until we find a match or exhaust our tuples
*
* Note: it's okay to use dlist_foreach here, even though we modify the
* dlist within the loop, because we don't continue the loop afterwards.
*/ */
bucket = &cache->cc_bucket[hashIndex]; bucket = &cache->cc_bucket[hashIndex];
dlist_foreach(iter, bucket)
dlist_foreach_modify(iter, bucket)
{ {
bool res; bool res;
@ -1382,6 +1384,9 @@ SearchCatCacheList(CatCache *cache,
/* /*
* scan the items until we find a match or exhaust our list * scan the items until we find a match or exhaust our list
*
* Note: it's okay to use dlist_foreach here, even though we modify the
* dlist within the loop, because we don't continue the loop afterwards.
*/ */
dlist_foreach(iter, &cache->cc_lists) dlist_foreach(iter, &cache->cc_lists)
{ {
@ -1807,11 +1812,11 @@ PrepareToInvalidateCacheTuple(Relation relation,
* ---------------- * ----------------
*/ */
slist_foreach(iter, &(CacheHdr->ch_caches)) slist_foreach(iter, &CacheHdr->ch_caches)
{ {
CatCache *ccp = slist_container(CatCache, cc_next, iter.cur);
uint32 hashvalue; uint32 hashvalue;
Oid dbid; Oid dbid;
CatCache *ccp = slist_container(CatCache, cc_next, iter.cur);
if (ccp->cc_reloid != reloid) if (ccp->cc_reloid != reloid)
continue; continue;