1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-04 20:11:56 +03:00

Remove CatalogCacheFlushRelation, and the reloidattr infrastructure that was

needed by nothing else.

The restructuring I just finished doing on cache management exposed to me how
silly this routine was.  Its function was to go into the catcache and blow
away all entries related to a given relation when there was a relcache flush
on that relation.  However, there is no point in removing a catcache entry
if the catalog row it represents is still valid --- and if it isn't valid,
there must have been a catcache entry flush on it, because that's triggered
directly by heap_update or heap_delete on the catalog row.  So this routine
accomplished nothing except to blow away valid cache entries that we'd very
likely be wanting in the near future to help reconstruct the relcache entry.
Dumb.

On top of which, it required a subtle and easy-to-get-wrong attribute in
syscache definitions, ie, the column containing the OID of the related
relation if any.  Removing that is a very useful maintenance simplification.
This commit is contained in:
Tom Lane
2010-02-08 05:53:55 +00:00
parent 68446b2c87
commit 9a75803b1a
4 changed files with 6 additions and 167 deletions

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.149 2010/02/07 20:48:10 tgl Exp $
* $PostgreSQL: pgsql/src/backend/utils/cache/catcache.c,v 1.150 2010/02/08 05:53:55 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -672,91 +672,6 @@ ResetCatalogCaches(void)
CACHE1_elog(DEBUG2, "end of ResetCatalogCaches call");
}
/*
* CatalogCacheFlushRelation
*
* This is called by RelationFlushRelation() to clear out cached information
* about a relation being dropped. (This could be a DROP TABLE command,
* or a temp table being dropped at end of transaction, or a table created
* during the current transaction that is being dropped because of abort.)
* Remove all cache entries relevant to the specified relation OID.
*/
void
CatalogCacheFlushRelation(Oid relId)
{
CatCache *cache;
CACHE2_elog(DEBUG2, "CatalogCacheFlushRelation called for %u", relId);
for (cache = CacheHdr->ch_caches; cache; cache = cache->cc_next)
{
int i;
/* We can ignore uninitialized caches, since they must be empty */
if (cache->cc_tupdesc == NULL)
continue;
/* Does this cache store tuples associated with relations at all? */
if (cache->cc_reloidattr == 0)
continue; /* nope, leave it alone */
/* Yes, scan the tuples and remove those related to relId */
for (i = 0; i < cache->cc_nbuckets; i++)
{
Dlelem *elt,
*nextelt;
for (elt = DLGetHead(&cache->cc_bucket[i]); elt; elt = nextelt)
{
CatCTup *ct = (CatCTup *) DLE_VAL(elt);
Oid tupRelid;
nextelt = DLGetSucc(elt);
/*
* Negative entries are never considered related to a rel,
* even if the rel is part of their lookup key.
*/
if (ct->negative)
continue;
if (cache->cc_reloidattr == ObjectIdAttributeNumber)
tupRelid = HeapTupleGetOid(&ct->tuple);
else
{
bool isNull;
tupRelid =
DatumGetObjectId(fastgetattr(&ct->tuple,
cache->cc_reloidattr,
cache->cc_tupdesc,
&isNull));
Assert(!isNull);
}
if (tupRelid == relId)
{
if (ct->refcount > 0 ||
(ct->c_list && ct->c_list->refcount > 0))
{
ct->dead = true;
/* parent list must be considered dead too */
if (ct->c_list)
ct->c_list->dead = true;
}
else
CatCacheRemoveCTup(cache, ct);
#ifdef CATCACHE_STATS
cache->cc_invals++;
#endif
}
}
}
}
CACHE1_elog(DEBUG2, "end of CatalogCacheFlushRelation call");
}
/*
* CatalogCacheFlushCatalog
*
@@ -820,7 +735,6 @@ CatCache *
InitCatCache(int id,
Oid reloid,
Oid indexoid,
int reloidattr,
int nkeys,
const int *key,
int nbuckets)
@@ -884,7 +798,6 @@ InitCatCache(int id,
cp->cc_indexoid = indexoid;
cp->cc_relisshared = false; /* temporary */
cp->cc_tupdesc = (TupleDesc) NULL;
cp->cc_reloidattr = reloidattr;
cp->cc_ntup = 0;
cp->cc_nbuckets = nbuckets;
cp->cc_nkeys = nkeys;