MCPcopy Create free account
hub / github.com/apache/cloudberry / RelationDecrementReferenceCount

Function RelationDecrementReferenceCount

src/backend/utils/cache/relcache.c:2240–6925  ·  view source on GitHub ↗

* RelationDecrementReferenceCount * Decrements relation reference count. */

Source from the content-addressed store, hash-verified

2238 * Decrements relation reference count.
2239 */
2240void
2241RelationDecrementReferenceCount(Relation rel)
2242{
2243 if (rel->rd_refcnt <= 0)
2244 {
2245 /*
2246 * In CI intermittently ERROR is seen. To help debug the issue, just
2247 * for debug builds elevating ERROR to PANIC.
2248 */
2249#ifdef USE_ASSERT_CHECKING
2250 elog(PANIC,
2251#else
2252 elog(ERROR,
2253#endif
2254 "Relation decrement reference count found relation %u/%u/%u with bad count (reference count %d)",
2255 rel->rd_node.spcNode,
2256 rel->rd_node.dbNode,
2257 rel->rd_node.relNode,
2258 rel->rd_refcnt);
2259 }
2260
2261 rel->rd_refcnt -= 1;
2262 if (!IsBootstrapProcessingMode())
2263 ResourceOwnerForgetRelationRef(CurrentResourceOwner, rel);
2264}
2265
2266/*
2267 * RelationClose - close an open relation
2268 *
2269 * Actually, we just decrement the refcount.
2270 *
2271 * NOTE: if compiled with -DRELCACHE_FORCE_RELEASE then relcache entries
2272 * will be freed as soon as their refcount goes to zero. In combination
2273 * with aset.c's CLOBBER_FREED_MEMORY option, this provides a good test
2274 * to catch references to already-released relcache entries. It slows
2275 * things down quite a bit, however.
2276 */
2277void
2278RelationClose(Relation relation)
2279{
2280 /* Note: no locking manipulations needed */
2281 RelationDecrementReferenceCount(relation);
2282
2283 /*
2284 * If the relation is no longer open in this session, we can clean up any
2285 * stale partition descriptors it has. This is unlikely, so check to see
2286 * if there are child contexts before expending a call to mcxt.c.
2287 */
2288 if (RelationHasReferenceCountZero(relation))
2289 {
2290 if (relation->rd_pdcxt != NULL &&
2291 relation->rd_pdcxt->firstchild != NULL)
2292 MemoryContextDeleteChildren(relation->rd_pdcxt);
2293
2294 if (relation->rd_pddcxt != NULL &&
2295 relation->rd_pddcxt->firstchild != NULL)
2296 MemoryContextDeleteChildren(relation->rd_pddcxt);
2297 }

Callers 11

RelationCloseFunction · 0.85
RelationFlushRelationFunction · 0.85
appendonly_endscanFunction · 0.85
appendonly_fetch_finishFunction · 0.85
heap_endscanFunction · 0.85
index_endscanFunction · 0.85
aocs_endscanFunction · 0.85
aocs_fetch_finishFunction · 0.85
external_endscanFunction · 0.85

Calls 1

Tested by

no test coverage detected