In PrepareToInvalidateCacheTuple, don't force initialization of catalog
authorTom Lane <[email protected]>
Wed, 5 Mar 2008 17:01:33 +0000 (17:01 +0000)
committerTom Lane <[email protected]>
Wed, 5 Mar 2008 17:01:33 +0000 (17:01 +0000)
caches that we don't actually need to touch.  This saves some trivial
number of cycles and avoids certain cases of deadlock when doing concurrent
VACUUM FULL on system catalogs.  Per report from Gavin Roy.

Backpatch to 8.2.  In earlier versions, CatalogCacheInitializeCache didn't
lock the relation so there's no deadlock risk (though that certainly had
plenty of risks of its own).

src/backend/utils/cache/catcache.c

index 1cb2f7c8e4d9d356ecc4091675e9d1cc60830a2d..8cbf49458f432f433aadb6bc136b6b376513c756 100644 (file)
@@ -1781,13 +1781,13 @@ PrepareToInvalidateCacheTuple(Relation relation,
 
        for (ccp = CacheHdr->ch_caches; ccp; ccp = ccp->cc_next)
        {
+               if (ccp->cc_reloid != reloid)
+                       continue;
+
                /* Just in case cache hasn't finished initialization yet... */
                if (ccp->cc_tupdesc == NULL)
                        CatalogCacheInitializeCache(ccp);
 
-               if (ccp->cc_reloid != reloid)
-                       continue;
-
                (*function) (ccp->id,
                                         CatalogCacheComputeTupleHashValue(ccp, tuple),
                                         &tuple->t_self,