* PrepareToInvalidateCacheTuple() * * This is part of a rather subtle chain of events, so pay attention: * * When a tuple is inserted or deleted, it cannot be flushed from the * catcaches immediately, for reasons explained at the top of cache/inval.c. * Instead we have to add entry(s) for the tuple to a list of pending tuple * invalidations that will be done at the end of the command or tra
| 2071 | * system relation. |
| 2072 | */ |
| 2073 | void |
| 2074 | PrepareToInvalidateCacheTuple(Relation relation, |
| 2075 | HeapTuple tuple, |
| 2076 | HeapTuple newtuple, |
| 2077 | void (*function) (int, uint32, Oid)) |
| 2078 | { |
| 2079 | slist_iter iter; |
| 2080 | Oid reloid; |
| 2081 | |
| 2082 | CACHE_elog(DEBUG2, "PrepareToInvalidateCacheTuple: called"); |
| 2083 | |
| 2084 | /* |
| 2085 | * sanity checks |
| 2086 | */ |
| 2087 | Assert(RelationIsValid(relation)); |
| 2088 | Assert(HeapTupleIsValid(tuple)); |
| 2089 | Assert(function != NULL); |
| 2090 | Assert(PointerIsValid(function)); |
| 2091 | Assert(CacheHdr != NULL); |
| 2092 | |
| 2093 | reloid = RelationGetRelid(relation); |
| 2094 | |
| 2095 | /* ---------------- |
| 2096 | * for each cache |
| 2097 | * if the cache contains tuples from the specified relation |
| 2098 | * compute the tuple's hash value(s) in this cache, |
| 2099 | * and call the passed function to register the information. |
| 2100 | * ---------------- |
| 2101 | */ |
| 2102 | |
| 2103 | slist_foreach(iter, &CacheHdr->ch_caches) |
| 2104 | { |
| 2105 | CatCache *ccp = slist_container(CatCache, cc_next, iter.cur); |
| 2106 | uint32 hashvalue; |
| 2107 | Oid dbid; |
| 2108 | |
| 2109 | if (ccp->cc_reloid != reloid) |
| 2110 | continue; |
| 2111 | |
| 2112 | /* Just in case cache hasn't finished initialization yet... */ |
| 2113 | if (ccp->cc_tupdesc == NULL) |
| 2114 | CatalogCacheInitializeCache(ccp); |
| 2115 | |
| 2116 | hashvalue = CatalogCacheComputeTupleHashValue(ccp, ccp->cc_nkeys, tuple); |
| 2117 | dbid = ccp->cc_relisshared ? (Oid) 0 : MyDatabaseId; |
| 2118 | |
| 2119 | (*function) (ccp->id, hashvalue, dbid); |
| 2120 | |
| 2121 | if (newtuple) |
| 2122 | { |
| 2123 | uint32 newhashvalue; |
| 2124 | |
| 2125 | newhashvalue = CatalogCacheComputeTupleHashValue(ccp, ccp->cc_nkeys, newtuple); |
| 2126 | |
| 2127 | if (newhashvalue != hashvalue) |
| 2128 | (*function) (ccp->id, newhashvalue, dbid); |
| 2129 | } |
| 2130 | } |
no test coverage detected