Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 002191a

Browse files
committed
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.
1 parent dc5aeca commit 002191a

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/backend/utils/cache/catcache.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ CatCacheRemoveCTup(CatCache *cache, CatCTup *ct)
370370
return; /* nothing left to do */
371371
}
372372

373+
/* delink from linked list */
373374
dlist_delete(&ct->cache_elem);
374375

375376
/* free associated tuple data */
@@ -452,9 +453,9 @@ CatalogCacheIdInvalidate(int cacheId, uint32 hashValue)
452453
*/
453454
slist_foreach(cache_iter, &CacheHdr->ch_caches)
454455
{
456+
CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur);
455457
Index hashIndex;
456458
dlist_mutable_iter iter;
457-
CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur);
458459

459460
if (cacheId != ccp->id)
460461
continue;
@@ -555,7 +556,7 @@ AtEOXact_CatCache(bool isCommit)
555556
{
556557
slist_iter cache_iter;
557558

558-
slist_foreach(cache_iter, &(CacheHdr->ch_caches))
559+
slist_foreach(cache_iter, &CacheHdr->ch_caches)
559560
{
560561
CatCache *ccp = slist_container(CatCache, cc_next, cache_iter.cur);
561562
dlist_iter iter;
@@ -682,7 +683,7 @@ CatalogCacheFlushCatalog(Oid catId)
682683

683684
CACHE2_elog(DEBUG2, "CatalogCacheFlushCatalog called for %u", catId);
684685

685-
slist_foreach(iter, &(CacheHdr->ch_caches))
686+
slist_foreach(iter, &CacheHdr->ch_caches)
686687
{
687688
CatCache *cache = slist_container(CatCache, cc_next, iter.cur);
688689

@@ -770,8 +771,10 @@ InitCatCache(int id,
770771

771772
/*
772773
* allocate a new cache structure
774+
*
775+
* Note: we rely on zeroing to initialize all the dlist headers correctly
773776
*/
774-
cp = (CatCache *) palloc0(sizeof(CatCache) + nbuckets * sizeof(dlist_node));
777+
cp = (CatCache *) palloc0(sizeof(CatCache) + nbuckets * sizeof(dlist_head));
775778

776779
/*
777780
* initialize the cache's relation information for the relation
@@ -790,9 +793,6 @@ InitCatCache(int id,
790793
for (i = 0; i < nkeys; ++i)
791794
cp->cc_key[i] = key[i];
792795

793-
dlist_init(&cp->cc_lists);
794-
MemSet(&cp->cc_bucket, 0, nbuckets * sizeof(dlist_head));
795-
796796
/*
797797
* new cache is initialized as far as we can go for now. print some
798798
* debugging information, if appropriate.
@@ -1060,7 +1060,7 @@ SearchCatCache(CatCache *cache,
10601060
ScanKeyData cur_skey[CATCACHE_MAXKEYS];
10611061
uint32 hashValue;
10621062
Index hashIndex;
1063-
dlist_mutable_iter iter;
1063+
dlist_iter iter;
10641064
dlist_head *bucket;
10651065
CatCTup *ct;
10661066
Relation relation;
@@ -1094,10 +1094,12 @@ SearchCatCache(CatCache *cache,
10941094

10951095
/*
10961096
* scan the hash bucket until we find a match or exhaust our tuples
1097+
*
1098+
* Note: it's okay to use dlist_foreach here, even though we modify the
1099+
* dlist within the loop, because we don't continue the loop afterwards.
10971100
*/
10981101
bucket = &cache->cc_bucket[hashIndex];
1099-
1100-
dlist_foreach_modify(iter, bucket)
1102+
dlist_foreach(iter, bucket)
11011103
{
11021104
bool res;
11031105

@@ -1382,6 +1384,9 @@ SearchCatCacheList(CatCache *cache,
13821384

13831385
/*
13841386
* scan the items until we find a match or exhaust our list
1387+
*
1388+
* Note: it's okay to use dlist_foreach here, even though we modify the
1389+
* dlist within the loop, because we don't continue the loop afterwards.
13851390
*/
13861391
dlist_foreach(iter, &cache->cc_lists)
13871392
{
@@ -1807,11 +1812,11 @@ PrepareToInvalidateCacheTuple(Relation relation,
18071812
* ----------------
18081813
*/
18091814

1810-
slist_foreach(iter, &(CacheHdr->ch_caches))
1815+
slist_foreach(iter, &CacheHdr->ch_caches)
18111816
{
1817+
CatCache *ccp = slist_container(CatCache, cc_next, iter.cur);
18121818
uint32 hashvalue;
18131819
Oid dbid;
1814-
CatCache *ccp = slist_container(CatCache, cc_next, iter.cur);
18151820

18161821
if (ccp->cc_reloid != reloid)
18171822
continue;

0 commit comments

Comments
 (0)