*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
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
*
InitCatCache(int id,
Oid reloid,
Oid indexoid,
- int reloidattr,
int nkeys,
const int *key,
int nbuckets)
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;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/syscache.c,v 1.124 2010/01/05 21:53:59 rhaas Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/syscache.c,v 1.125 2010/02/08 05:53:55 tgl Exp $
*
* NOTES
* These routines allow the parser/planner/executor to perform
Add your entry to the cacheinfo[] array below. All cache lists are
alphabetical, so add it in the proper place. Specify the relation OID,
- index OID, number of keys, key attribute numbers, and number of hash
- buckets. If the relation contains tuples that are associated with a
- particular relation (for example, its attributes, rules, triggers, etc)
- then specify the attribute number that contains the OID of the associated
- relation. This is used by CatalogCacheFlushRelation() to remove the
- correct tuples during a table drop or relcache invalidation event.
+ index OID, number of keys, key attribute numbers, and initial number of
+ hash buckets.
The number of hash buckets must be a power of 2. It's reasonable to
set this to the number of entries that might be in the particular cache
{
Oid reloid; /* OID of the relation being cached */
Oid indoid; /* OID of index relation for this cache */
- int reloidattr; /* attr number of rel OID reference, or 0 */
int nkeys; /* # of keys needed for cache lookup */
int key[4]; /* attribute numbers of key attrs */
int nbuckets; /* number of hash buckets for this cache */
static const struct cachedesc cacheinfo[] = {
{AggregateRelationId, /* AGGFNOID */
AggregateFnoidIndexId,
- 0,
1,
{
Anum_pg_aggregate_aggfnoid,
},
{AccessMethodRelationId, /* AMNAME */
AmNameIndexId,
- 0,
1,
{
Anum_pg_am_amname,
},
{AccessMethodRelationId, /* AMOID */
AmOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{AccessMethodOperatorRelationId, /* AMOPOPID */
AccessMethodOperatorIndexId,
- 0,
2,
{
Anum_pg_amop_amopopr,
},
{AccessMethodOperatorRelationId, /* AMOPSTRATEGY */
AccessMethodStrategyIndexId,
- 0,
4,
{
Anum_pg_amop_amopfamily,
},
{AccessMethodProcedureRelationId, /* AMPROCNUM */
AccessMethodProcedureIndexId,
- 0,
4,
{
Anum_pg_amproc_amprocfamily,
},
{AttributeRelationId, /* ATTNAME */
AttributeRelidNameIndexId,
- Anum_pg_attribute_attrelid,
2,
{
Anum_pg_attribute_attrelid,
},
{AttributeRelationId, /* ATTNUM */
AttributeRelidNumIndexId,
- Anum_pg_attribute_attrelid,
2,
{
Anum_pg_attribute_attrelid,
},
{AuthMemRelationId, /* AUTHMEMMEMROLE */
AuthMemMemRoleIndexId,
- 0,
2,
{
Anum_pg_auth_members_member,
},
{AuthMemRelationId, /* AUTHMEMROLEMEM */
AuthMemRoleMemIndexId,
- 0,
2,
{
Anum_pg_auth_members_roleid,
},
{AuthIdRelationId, /* AUTHNAME */
AuthIdRolnameIndexId,
- 0,
1,
{
Anum_pg_authid_rolname,
},
{AuthIdRelationId, /* AUTHOID */
AuthIdOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
{
CastRelationId, /* CASTSOURCETARGET */
CastSourceTargetIndexId,
- 0,
2,
{
Anum_pg_cast_castsource,
},
{OperatorClassRelationId, /* CLAAMNAMENSP */
OpclassAmNameNspIndexId,
- 0,
3,
{
Anum_pg_opclass_opcmethod,
},
{OperatorClassRelationId, /* CLAOID */
OpclassOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{ConversionRelationId, /* CONDEFAULT */
ConversionDefaultIndexId,
- 0,
4,
{
Anum_pg_conversion_connamespace,
},
{ConversionRelationId, /* CONNAMENSP */
ConversionNameNspIndexId,
- 0,
2,
{
Anum_pg_conversion_conname,
},
{ConstraintRelationId, /* CONSTROID */
ConstraintOidIndexId,
- Anum_pg_constraint_conrelid,
1,
{
ObjectIdAttributeNumber,
},
{ConversionRelationId, /* CONVOID */
ConversionOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{DatabaseRelationId, /* DATABASEOID */
DatabaseOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{DefaultAclRelationId, /* DEFACLROLENSPOBJ */
DefaultAclRoleNspObjIndexId,
- 0,
3,
{
Anum_pg_default_acl_defaclrole,
},
{EnumRelationId, /* ENUMOID */
EnumOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{EnumRelationId, /* ENUMTYPOIDNAME */
EnumTypIdLabelIndexId,
- 0,
2,
{
Anum_pg_enum_enumtypid,
},
{ForeignDataWrapperRelationId, /* FOREIGNDATAWRAPPERNAME */
ForeignDataWrapperNameIndexId,
- 0,
1,
{
Anum_pg_foreign_data_wrapper_fdwname,
},
{ForeignDataWrapperRelationId, /* FOREIGNDATAWRAPPEROID */
ForeignDataWrapperOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{ForeignServerRelationId, /* FOREIGNSERVERNAME */
ForeignServerNameIndexId,
- 0,
1,
{
Anum_pg_foreign_server_srvname,
},
{ForeignServerRelationId, /* FOREIGNSERVEROID */
ForeignServerOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{IndexRelationId, /* INDEXRELID */
IndexRelidIndexId,
- Anum_pg_index_indrelid,
1,
{
Anum_pg_index_indexrelid,
},
{LanguageRelationId, /* LANGNAME */
LanguageNameIndexId,
- 0,
1,
{
Anum_pg_language_lanname,
},
{LanguageRelationId, /* LANGOID */
LanguageOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{NamespaceRelationId, /* NAMESPACENAME */
NamespaceNameIndexId,
- 0,
1,
{
Anum_pg_namespace_nspname,
},
{NamespaceRelationId, /* NAMESPACEOID */
NamespaceOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{OperatorRelationId, /* OPERNAMENSP */
OperatorNameNspIndexId,
- 0,
4,
{
Anum_pg_operator_oprname,
},
{OperatorRelationId, /* OPEROID */
OperatorOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{OperatorFamilyRelationId, /* OPFAMILYAMNAMENSP */
OpfamilyAmNameNspIndexId,
- 0,
3,
{
Anum_pg_opfamily_opfmethod,
},
{OperatorFamilyRelationId, /* OPFAMILYOID */
OpfamilyOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{ProcedureRelationId, /* PROCNAMEARGSNSP */
ProcedureNameArgsNspIndexId,
- 0,
3,
{
Anum_pg_proc_proname,
},
{ProcedureRelationId, /* PROCOID */
ProcedureOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{RelationRelationId, /* RELNAMENSP */
ClassNameNspIndexId,
- ObjectIdAttributeNumber,
2,
{
Anum_pg_class_relname,
},
{RelationRelationId, /* RELOID */
ClassOidIndexId,
- ObjectIdAttributeNumber,
1,
{
ObjectIdAttributeNumber,
},
{RewriteRelationId, /* RULERELNAME */
RewriteRelRulenameIndexId,
- Anum_pg_rewrite_ev_class,
2,
{
Anum_pg_rewrite_ev_class,
},
{StatisticRelationId, /* STATRELATTINH */
StatisticRelidAttnumInhIndexId,
- Anum_pg_statistic_starelid,
3,
{
Anum_pg_statistic_starelid,
},
{TableSpaceRelationId, /* TABLESPACEOID */
TablespaceOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{TSConfigMapRelationId, /* TSCONFIGMAP */
TSConfigMapIndexId,
- 0,
3,
{
Anum_pg_ts_config_map_mapcfg,
},
{TSConfigRelationId, /* TSCONFIGNAMENSP */
TSConfigNameNspIndexId,
- 0,
2,
{
Anum_pg_ts_config_cfgname,
},
{TSConfigRelationId, /* TSCONFIGOID */
TSConfigOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{TSDictionaryRelationId, /* TSDICTNAMENSP */
TSDictionaryNameNspIndexId,
- 0,
2,
{
Anum_pg_ts_dict_dictname,
},
{TSDictionaryRelationId, /* TSDICTOID */
TSDictionaryOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{TSParserRelationId, /* TSPARSERNAMENSP */
TSParserNameNspIndexId,
- 0,
2,
{
Anum_pg_ts_parser_prsname,
},
{TSParserRelationId, /* TSPARSEROID */
TSParserOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{TSTemplateRelationId, /* TSTEMPLATENAMENSP */
TSTemplateNameNspIndexId,
- 0,
2,
{
Anum_pg_ts_template_tmplname,
},
{TSTemplateRelationId, /* TSTEMPLATEOID */
TSTemplateOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{TypeRelationId, /* TYPENAMENSP */
TypeNameNspIndexId,
- Anum_pg_type_typrelid,
2,
{
Anum_pg_type_typname,
},
{TypeRelationId, /* TYPEOID */
TypeOidIndexId,
- Anum_pg_type_typrelid,
1,
{
ObjectIdAttributeNumber,
},
{UserMappingRelationId, /* USERMAPPINGOID */
UserMappingOidIndexId,
- 0,
1,
{
ObjectIdAttributeNumber,
},
{UserMappingRelationId, /* USERMAPPINGUSERSERVER */
UserMappingUserServerIndexId,
- 0,
2,
{
Anum_pg_user_mapping_umuser,
SysCache[cacheId] = InitCatCache(cacheId,
cacheinfo[cacheId].reloid,
cacheinfo[cacheId].indoid,
- cacheinfo[cacheId].reloidattr,
cacheinfo[cacheId].nkeys,
cacheinfo[cacheId].key,
cacheinfo[cacheId].nbuckets);