@@ -435,21 +435,14 @@ CatCacheRemoveCList(CatCache *cache, CatCList *cl)
435
435
* target tuple that has to be invalidated has a different TID than it
436
436
* did when the event was created. So now we just compare hash values and
437
437
* accept the small risk of unnecessary invalidations due to false matches.
438
- * (The ItemPointer argument is therefore useless and should get removed.)
439
438
*
440
439
* This routine is only quasi-public: it should only be used by inval.c.
441
440
*/
442
441
void
443
- CatalogCacheIdInvalidate (int cacheId ,
444
- uint32 hashValue ,
445
- ItemPointer pointer )
442
+ CatalogCacheIdInvalidate (int cacheId , uint32 hashValue )
446
443
{
447
444
CatCache * ccp ;
448
445
449
- /*
450
- * sanity checks
451
- */
452
- Assert (ItemPointerIsValid (pointer ));
453
446
CACHE1_elog (DEBUG2 , "CatalogCacheIdInvalidate: called" );
454
447
455
448
/*
@@ -699,7 +692,7 @@ CatalogCacheFlushCatalog(Oid catId)
699
692
ResetCatalogCache (cache );
700
693
701
694
/* Tell inval.c to call syscache callbacks for this cache */
702
- CallSyscacheCallbacks (cache -> id , NULL );
695
+ CallSyscacheCallbacks (cache -> id , 0 );
703
696
}
704
697
}
705
698
@@ -1708,11 +1701,16 @@ build_dummy_tuple(CatCache *cache, int nkeys, ScanKey skeys)
1708
1701
* The lists of tuples that need to be flushed are kept by inval.c. This
1709
1702
* routine is a helper routine for inval.c. Given a tuple belonging to
1710
1703
* 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,
1714
1707
* using the recorded information.
1715
1708
*
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
+ *
1716
1714
* Note that it is irrelevant whether the given tuple is actually loaded
1717
1715
* into the catcache at the moment. Even if it's not there now, it might
1718
1716
* 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)
1727
1725
void
1728
1726
PrepareToInvalidateCacheTuple (Relation relation ,
1729
1727
HeapTuple tuple ,
1730
- void (* function ) (int , uint32 , ItemPointer , Oid ))
1728
+ HeapTuple newtuple ,
1729
+ void (* function ) (int , uint32 , Oid ))
1731
1730
{
1732
1731
CatCache * ccp ;
1733
1732
Oid reloid ;
@@ -1747,24 +1746,37 @@ PrepareToInvalidateCacheTuple(Relation relation,
1747
1746
/* ----------------
1748
1747
* for each cache
1749
1748
* 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,
1751
1750
* and call the passed function to register the information.
1752
1751
* ----------------
1753
1752
*/
1754
1753
1755
1754
for (ccp = CacheHdr -> ch_caches ; ccp ; ccp = ccp -> cc_next )
1756
1755
{
1756
+ uint32 hashvalue ;
1757
+ Oid dbid ;
1758
+
1757
1759
if (ccp -> cc_reloid != reloid )
1758
1760
continue ;
1759
1761
1760
1762
/* Just in case cache hasn't finished initialization yet... */
1761
1763
if (ccp -> cc_tupdesc == NULL )
1762
1764
CatalogCacheInitializeCache (ccp );
1763
1765
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
+ }
1768
1780
}
1769
1781
}
1770
1782
0 commit comments