@@ -370,6 +370,7 @@ CatCacheRemoveCTup(CatCache *cache, CatCTup *ct)
370
370
return ; /* nothing left to do */
371
371
}
372
372
373
+ /* delink from linked list */
373
374
dlist_delete (& ct -> cache_elem );
374
375
375
376
/* free associated tuple data */
@@ -452,9 +453,9 @@ CatalogCacheIdInvalidate(int cacheId, uint32 hashValue)
452
453
*/
453
454
slist_foreach (cache_iter , & CacheHdr -> ch_caches )
454
455
{
456
+ CatCache * ccp = slist_container (CatCache , cc_next , cache_iter .cur );
455
457
Index hashIndex ;
456
458
dlist_mutable_iter iter ;
457
- CatCache * ccp = slist_container (CatCache , cc_next , cache_iter .cur );
458
459
459
460
if (cacheId != ccp -> id )
460
461
continue ;
@@ -555,7 +556,7 @@ AtEOXact_CatCache(bool isCommit)
555
556
{
556
557
slist_iter cache_iter ;
557
558
558
- slist_foreach (cache_iter , & ( CacheHdr -> ch_caches ) )
559
+ slist_foreach (cache_iter , & CacheHdr -> ch_caches )
559
560
{
560
561
CatCache * ccp = slist_container (CatCache , cc_next , cache_iter .cur );
561
562
dlist_iter iter ;
@@ -682,7 +683,7 @@ CatalogCacheFlushCatalog(Oid catId)
682
683
683
684
CACHE2_elog (DEBUG2 , "CatalogCacheFlushCatalog called for %u" , catId );
684
685
685
- slist_foreach (iter , & ( CacheHdr -> ch_caches ) )
686
+ slist_foreach (iter , & CacheHdr -> ch_caches )
686
687
{
687
688
CatCache * cache = slist_container (CatCache , cc_next , iter .cur );
688
689
@@ -770,8 +771,10 @@ InitCatCache(int id,
770
771
771
772
/*
772
773
* allocate a new cache structure
774
+ *
775
+ * Note: we rely on zeroing to initialize all the dlist headers correctly
773
776
*/
774
- cp = (CatCache * ) palloc0 (sizeof (CatCache ) + nbuckets * sizeof (dlist_node ));
777
+ cp = (CatCache * ) palloc0 (sizeof (CatCache ) + nbuckets * sizeof (dlist_head ));
775
778
776
779
/*
777
780
* initialize the cache's relation information for the relation
@@ -790,9 +793,6 @@ InitCatCache(int id,
790
793
for (i = 0 ; i < nkeys ; ++ i )
791
794
cp -> cc_key [i ] = key [i ];
792
795
793
- dlist_init (& cp -> cc_lists );
794
- MemSet (& cp -> cc_bucket , 0 , nbuckets * sizeof (dlist_head ));
795
-
796
796
/*
797
797
* new cache is initialized as far as we can go for now. print some
798
798
* debugging information, if appropriate.
@@ -1060,7 +1060,7 @@ SearchCatCache(CatCache *cache,
1060
1060
ScanKeyData cur_skey [CATCACHE_MAXKEYS ];
1061
1061
uint32 hashValue ;
1062
1062
Index hashIndex ;
1063
- dlist_mutable_iter iter ;
1063
+ dlist_iter iter ;
1064
1064
dlist_head * bucket ;
1065
1065
CatCTup * ct ;
1066
1066
Relation relation ;
@@ -1094,10 +1094,12 @@ SearchCatCache(CatCache *cache,
1094
1094
1095
1095
/*
1096
1096
* 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.
1097
1100
*/
1098
1101
bucket = & cache -> cc_bucket [hashIndex ];
1099
-
1100
- dlist_foreach_modify (iter , bucket )
1102
+ dlist_foreach (iter , bucket )
1101
1103
{
1102
1104
bool res ;
1103
1105
@@ -1382,6 +1384,9 @@ SearchCatCacheList(CatCache *cache,
1382
1384
1383
1385
/*
1384
1386
* 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.
1385
1390
*/
1386
1391
dlist_foreach (iter , & cache -> cc_lists )
1387
1392
{
@@ -1807,11 +1812,11 @@ PrepareToInvalidateCacheTuple(Relation relation,
1807
1812
* ----------------
1808
1813
*/
1809
1814
1810
- slist_foreach (iter , & ( CacheHdr -> ch_caches ) )
1815
+ slist_foreach (iter , & CacheHdr -> ch_caches )
1811
1816
{
1817
+ CatCache * ccp = slist_container (CatCache , cc_next , iter .cur );
1812
1818
uint32 hashvalue ;
1813
1819
Oid dbid ;
1814
- CatCache * ccp = slist_container (CatCache , cc_next , iter .cur );
1815
1820
1816
1821
if (ccp -> cc_reloid != reloid )
1817
1822
continue ;
0 commit comments