@@ -435,21 +435,14 @@ CatCacheRemoveCList(CatCache *cache, CatCList *cl)
435435 * target tuple that has to be invalidated has a different TID than it
436436 * did when the event was created. So now we just compare hash values and
437437 * accept the small risk of unnecessary invalidations due to false matches.
438- * (The ItemPointer argument is therefore useless and should get removed.)
439438 *
440439 * This routine is only quasi-public: it should only be used by inval.c.
441440 */
442441void
443- CatalogCacheIdInvalidate (int cacheId ,
444- uint32 hashValue ,
445- ItemPointer pointer )
442+ CatalogCacheIdInvalidate (int cacheId , uint32 hashValue )
446443{
447444 CatCache * ccp ;
448445
449- /*
450- * sanity checks
451- */
452- Assert (ItemPointerIsValid (pointer ));
453446 CACHE1_elog (DEBUG2 , "CatalogCacheIdInvalidate: called" );
454447
455448 /*
@@ -699,7 +692,7 @@ CatalogCacheFlushCatalog(Oid catId)
699692 ResetCatalogCache (cache );
700693
701694 /* Tell inval.c to call syscache callbacks for this cache */
702- CallSyscacheCallbacks (cache -> id , NULL );
695+ CallSyscacheCallbacks (cache -> id , 0 );
703696 }
704697 }
705698
@@ -1708,11 +1701,16 @@ build_dummy_tuple(CatCache *cache, int nkeys, ScanKey skeys)
17081701 * The lists of tuples that need to be flushed are kept by inval.c. This
17091702 * routine is a helper routine for inval.c. Given a tuple belonging to
17101703 * the specified relation, find all catcaches it could be in, compute the
1711- * correct hash value for each such catcache, and call the specified function
1712- * to record the cache id, hash value, and tuple ItemPointer in inval.c's
1713- * lists. CatalogCacheIdInvalidate will be called later, if appropriate,
1704+ * correct hash value for each such catcache, and call the specified
1705+ * function to record the cache id and hash value in inval.c's lists.
1706+ * CatalogCacheIdInvalidate will be called later, if appropriate,
17141707 * using the recorded information.
17151708 *
1709+ * For an insert or delete, tuple is the target tuple and newtuple is NULL.
1710+ * For an update, we are called just once, with tuple being the old tuple
1711+ * version and newtuple the new version. We should make two list entries
1712+ * if the tuple's hash value changed, but only one if it didn't.
1713+ *
17161714 * Note that it is irrelevant whether the given tuple is actually loaded
17171715 * into the catcache at the moment. Even if it's not there now, it might
17181716 * be by the end of the command, or there might be a matching negative entry
@@ -1727,7 +1725,8 @@ build_dummy_tuple(CatCache *cache, int nkeys, ScanKey skeys)
17271725void
17281726PrepareToInvalidateCacheTuple (Relation relation ,
17291727 HeapTuple tuple ,
1730- void (* function ) (int , uint32 , ItemPointer , Oid ))
1728+ HeapTuple newtuple ,
1729+ void (* function ) (int , uint32 , Oid ))
17311730{
17321731 CatCache * ccp ;
17331732 Oid reloid ;
@@ -1747,24 +1746,37 @@ PrepareToInvalidateCacheTuple(Relation relation,
17471746 /* ----------------
17481747 * for each cache
17491748 * if the cache contains tuples from the specified relation
1750- * compute the tuple's hash value in this cache,
1749+ * compute the tuple's hash value(s) in this cache,
17511750 * and call the passed function to register the information.
17521751 * ----------------
17531752 */
17541753
17551754 for (ccp = CacheHdr -> ch_caches ; ccp ; ccp = ccp -> cc_next )
17561755 {
1756+ uint32 hashvalue ;
1757+ Oid dbid ;
1758+
17571759 if (ccp -> cc_reloid != reloid )
17581760 continue ;
17591761
17601762 /* Just in case cache hasn't finished initialization yet... */
17611763 if (ccp -> cc_tupdesc == NULL )
17621764 CatalogCacheInitializeCache (ccp );
17631765
1764- (* function ) (ccp -> id ,
1765- CatalogCacheComputeTupleHashValue (ccp , tuple ),
1766- & tuple -> t_self ,
1767- ccp -> cc_relisshared ? (Oid ) 0 : MyDatabaseId );
1766+ hashvalue = CatalogCacheComputeTupleHashValue (ccp , tuple );
1767+ dbid = ccp -> cc_relisshared ? (Oid ) 0 : MyDatabaseId ;
1768+
1769+ (* function ) (ccp -> id , hashvalue , dbid );
1770+
1771+ if (newtuple )
1772+ {
1773+ uint32 newhashvalue ;
1774+
1775+ newhashvalue = CatalogCacheComputeTupleHashValue (ccp , newtuple );
1776+
1777+ if (newhashvalue != hashvalue )
1778+ (* function ) (ccp -> id , newhashvalue , dbid );
1779+ }
17681780 }
17691781}
17701782
0 commit comments