PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
syscache.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/indexing.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
#include "catalog/pg_db_role_setting.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_depend.h"
#include "catalog/pg_description.h"
#include "catalog/pg_enum.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_foreign_table.h"
#include "catalog/pg_language.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_partitioned_table.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_range.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_seclabel.h"
#include "catalog/pg_sequence.h"
#include "catalog/pg_shdepend.h"
#include "catalog/pg_shdescription.h"
#include "catalog/pg_shseclabel.h"
#include "catalog/pg_replication_origin.h"
#include "catalog/pg_statistic.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_subscription_rel.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_config_map.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "utils/rel.h"
#include "utils/catcache.h"
#include "utils/syscache.h"
Include dependency graph for syscache.c:

Go to the source code of this file.

Data Structures

struct  cachedesc
 

Macros

#define SysCacheSize   ((int) lengthof(cacheinfo))
 

Functions

static int oid_compare (const void *a, const void *b)
 
void InitCatalogCache (void)
 
void InitCatalogCachePhase2 (void)
 
HeapTuple SearchSysCache (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
void ReleaseSysCache (HeapTuple tuple)
 
HeapTuple SearchSysCacheCopy (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
bool SearchSysCacheExists (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
Oid GetSysCacheOid (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
HeapTuple SearchSysCacheAttName (Oid relid, const char *attname)
 
HeapTuple SearchSysCacheCopyAttName (Oid relid, const char *attname)
 
bool SearchSysCacheExistsAttName (Oid relid, const char *attname)
 
Datum SysCacheGetAttr (int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
 
uint32 GetSysCacheHashValue (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
struct catclistSearchSysCacheList (int cacheId, int nkeys, Datum key1, Datum key2, Datum key3, Datum key4)
 
bool RelationInvalidatesSnapshotsOnly (Oid relid)
 
bool RelationHasSysCache (Oid relid)
 
bool RelationSupportsSysCache (Oid relid)
 

Variables

static const struct cachedesc cacheinfo []
 
static CatCacheSysCache [SysCacheSize]
 
static bool CacheInitialized = false
 
static Oid SysCacheRelationOid [SysCacheSize]
 
static int SysCacheRelationOidSize
 
static Oid SysCacheSupportingRelOid [SysCacheSize *2]
 
static int SysCacheSupportingRelOidSize
 

Macro Definition Documentation

#define SysCacheSize   ((int) lengthof(cacheinfo))

Function Documentation

uint32 GetSysCacheHashValue ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 1313 of file syscache.c.

References elog, ERROR, GetCatCacheHashValue(), PointerIsValid, and SysCacheSize.

1318 {
1319  if (cacheId < 0 || cacheId >= SysCacheSize ||
1320  !PointerIsValid(SysCache[cacheId]))
1321  elog(ERROR, "invalid cache ID: %d", cacheId);
1322 
1323  return GetCatCacheHashValue(SysCache[cacheId], key1, key2, key3, key4);
1324 }
#define ERROR
Definition: elog.h:43
#define SysCacheSize
Definition: syscache.c:974
static CatCache * SysCache[SysCacheSize]
Definition: syscache.c:976
#define elog
Definition: elog.h:219
uint32 GetCatCacheHashValue(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
Definition: catcache.c:1349
#define PointerIsValid(pointer)
Definition: c.h:526
Oid GetSysCacheOid ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 1177 of file syscache.c.

References HeapTupleGetOid, HeapTupleIsValid, InvalidOid, ReleaseSysCache(), result, and SearchSysCache().

1182 {
1183  HeapTuple tuple;
1184  Oid result;
1185 
1186  tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
1187  if (!HeapTupleIsValid(tuple))
1188  return InvalidOid;
1189  result = HeapTupleGetOid(tuple);
1190  ReleaseSysCache(tuple);
1191  return result;
1192 }
HeapTuple SearchSysCache(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1098
return result
Definition: formatting.c:1618
unsigned int Oid
Definition: postgres_ext.h:31
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
void InitCatalogCache ( void  )

Definition at line 1000 of file syscache.c.

References Assert, CacheInitialized, elog, ERROR, i, cachedesc::indoid, InitCatCache(), cachedesc::key, lengthof, cachedesc::nbuckets, cachedesc::nkeys, oid_compare(), pg_qsort(), PointerIsValid, RelationInvalidatesSnapshotsOnly(), cachedesc::reloid, SysCacheRelationOid, SysCacheRelationOidSize, SysCacheSize, SysCacheSupportingRelOid, and SysCacheSupportingRelOidSize.

Referenced by InitPostgres().

1001 {
1002  int cacheId;
1003  int i,
1004  j;
1005 
1007 
1009 
1010  for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
1011  {
1012  SysCache[cacheId] = InitCatCache(cacheId,
1013  cacheinfo[cacheId].reloid,
1014  cacheinfo[cacheId].indoid,
1015  cacheinfo[cacheId].nkeys,
1016  cacheinfo[cacheId].key,
1017  cacheinfo[cacheId].nbuckets);
1018  if (!PointerIsValid(SysCache[cacheId]))
1019  elog(ERROR, "could not initialize cache %u (%d)",
1020  cacheinfo[cacheId].reloid, cacheId);
1021  /* Accumulate data for OID lists, too */
1023  cacheinfo[cacheId].reloid;
1025  cacheinfo[cacheId].reloid;
1027  cacheinfo[cacheId].indoid;
1028  /* see comments for RelationInvalidatesSnapshotsOnly */
1030  }
1031 
1034 
1035  /* Sort and de-dup OID arrays, so we can use binary search. */
1037  sizeof(Oid), oid_compare);
1038  for (i = 1, j = 0; i < SysCacheRelationOidSize; i++)
1039  {
1042  }
1043  SysCacheRelationOidSize = j + 1;
1044 
1046  sizeof(Oid), oid_compare);
1047  for (i = 1, j = 0; i < SysCacheSupportingRelOidSize; i++)
1048  {
1051  }
1052  SysCacheSupportingRelOidSize = j + 1;
1053 
1054  CacheInitialized = true;
1055 }
static bool CacheInitialized
Definition: syscache.c:978
static int SysCacheSupportingRelOidSize
Definition: syscache.c:986
static Oid SysCacheSupportingRelOid[SysCacheSize *2]
Definition: syscache.c:985
static int SysCacheRelationOidSize
Definition: syscache.c:982
#define lengthof(array)
Definition: c.h:562
unsigned int Oid
Definition: postgres_ext.h:31
static const struct cachedesc cacheinfo[]
Definition: syscache.c:123
Oid reloid
Definition: syscache.c:116
#define ERROR
Definition: elog.h:43
#define SysCacheSize
Definition: syscache.c:974
CatCache * InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, const int *key, int nbuckets)
Definition: catcache.c:719
Oid indoid
Definition: syscache.c:117
static CatCache * SysCache[SysCacheSize]
Definition: syscache.c:976
static Oid SysCacheRelationOid[SysCacheSize]
Definition: syscache.c:981
#define Assert(condition)
Definition: c.h:675
bool RelationInvalidatesSnapshotsOnly(Oid relid)
Definition: syscache.c:1353
void pg_qsort(void *base, size_t nel, size_t elsize, int(*cmp)(const void *, const void *))
Definition: qsort.c:113
static int oid_compare(const void *a, const void *b)
Definition: syscache.c:1426
int i
#define elog
Definition: elog.h:219
#define PointerIsValid(pointer)
Definition: c.h:526
void InitCatalogCachePhase2 ( void  )

Definition at line 1070 of file syscache.c.

References Assert, CacheInitialized, InitCatCachePhase2(), and SysCacheSize.

Referenced by RelationCacheInitializePhase3().

1071 {
1072  int cacheId;
1073 
1075 
1076  for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
1077  InitCatCachePhase2(SysCache[cacheId], true);
1078 }
static bool CacheInitialized
Definition: syscache.c:978
#define SysCacheSize
Definition: syscache.c:974
static CatCache * SysCache[SysCacheSize]
Definition: syscache.c:976
#define Assert(condition)
Definition: c.h:675
void InitCatCachePhase2(CatCache *cache, bool touch_index)
Definition: catcache.c:988
static int oid_compare ( const void *  a,
const void *  b 
)
static

Definition at line 1426 of file syscache.c.

Referenced by InitCatalogCache().

1427 {
1428  Oid oa = *((const Oid *) a);
1429  Oid ob = *((const Oid *) b);
1430 
1431  if (oa == ob)
1432  return 0;
1433  return (oa > ob) ? 1 : -1;
1434 }
unsigned int Oid
Definition: postgres_ext.h:31
bool RelationHasSysCache ( Oid  relid)

Definition at line 1376 of file syscache.c.

References SysCacheRelationOid, and SysCacheRelationOidSize.

Referenced by GetNonHistoricCatalogSnapshot().

1377 {
1378  int low = 0,
1379  high = SysCacheRelationOidSize - 1;
1380 
1381  while (low <= high)
1382  {
1383  int middle = low + (high - low) / 2;
1384 
1385  if (SysCacheRelationOid[middle] == relid)
1386  return true;
1387  if (SysCacheRelationOid[middle] < relid)
1388  low = middle + 1;
1389  else
1390  high = middle - 1;
1391  }
1392 
1393  return false;
1394 }
static int SysCacheRelationOidSize
Definition: syscache.c:982
static Oid SysCacheRelationOid[SysCacheSize]
Definition: syscache.c:981
bool RelationInvalidatesSnapshotsOnly ( Oid  relid)

Definition at line 1353 of file syscache.c.

References DbRoleSettingRelationId, DependRelationId, DescriptionRelationId, SecLabelRelationId, SharedDependRelationId, SharedDescriptionRelationId, and SharedSecLabelRelationId.

Referenced by CacheInvalidateHeapTuple(), GetNonHistoricCatalogSnapshot(), and InitCatalogCache().

1354 {
1355  switch (relid)
1356  {
1358  case DependRelationId:
1360  case DescriptionRelationId:
1362  case SecLabelRelationId:
1364  return true;
1365  default:
1366  break;
1367  }
1368 
1369  return false;
1370 }
#define SharedDependRelationId
Definition: pg_shdepend.h:29
#define DependRelationId
Definition: pg_depend.h:29
#define SharedDescriptionRelationId
#define SharedSecLabelRelationId
Definition: pg_shseclabel.h:21
#define SecLabelRelationId
Definition: pg_seclabel.h:21
#define DescriptionRelationId
#define DbRoleSettingRelationId
bool RelationSupportsSysCache ( Oid  relid)

Definition at line 1401 of file syscache.c.

References SysCacheSupportingRelOid, and SysCacheSupportingRelOidSize.

Referenced by RelationIdIsInInitFile().

1402 {
1403  int low = 0,
1404  high = SysCacheSupportingRelOidSize - 1;
1405 
1406  while (low <= high)
1407  {
1408  int middle = low + (high - low) / 2;
1409 
1410  if (SysCacheSupportingRelOid[middle] == relid)
1411  return true;
1412  if (SysCacheSupportingRelOid[middle] < relid)
1413  low = middle + 1;
1414  else
1415  high = middle - 1;
1416  }
1417 
1418  return false;
1419 }
static int SysCacheSupportingRelOidSize
Definition: syscache.c:986
static Oid SysCacheSupportingRelOid[SysCacheSize *2]
Definition: syscache.c:985
void ReleaseSysCache ( HeapTuple  tuple)

Definition at line 1116 of file syscache.c.

References ReleaseCatCache().

Referenced by aclitemout(), AddEnumLabel(), AddRoleMems(), AggregateCreate(), AlterDomainValidateConstraint(), AlterEnum(), AlterObjectRename_internal(), AlterOpFamily(), AlterRole(), AlterRoleSet(), AlterSchemaOwner(), AlterSchemaOwner_oid(), AlterTSConfiguration(), AlterTSDictionary(), AlterTypeOwner(), AlterTypeOwner_oid(), amvalidate(), appendAggOrderBy(), appendFunctionName(), assignOperTypes(), assignProcTypes(), ATAddForeignKeyConstraint(), ATExecAddColumn(), ATExecAddOf(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecChangeOwner(), ATExecDropColumn(), ATExecDropNotNull(), ATExecSetOptions(), ATExecSetRelOptions(), ATPostAlterTypeCleanup(), ATPrepAlterColumnType(), blvalidate(), brincostestimate(), brinvalidate(), btcostestimate(), btvalidate(), build_coercion_expression(), BuildIndexValueDescription(), BuildTupleRemapInfo(), CacheInvalidateRelcacheByRelid(), call_pltcl_start_proc(), check_amop_signature(), check_amproc_signature(), check_enable_rls(), check_for_column_name_collision(), check_hash_func_signature(), check_role(), check_safe_enum_use(), check_session_authorization(), check_TSCurrentConfig(), CheckFunctionValidatorAccess(), CheckIndexCompatible(), CheckMyDatabase(), cluster(), cluster_rel(), coerce_type(), CollationIsVisible(), column_privilege_check(), compatible_oper(), compatible_oper_opid(), compile_plperl_function(), compile_pltcl_function(), compute_return_type(), ComputeIndexAttrs(), ComputePartitionAttrs(), ConstructTupleDescriptor(), ConversionIsVisible(), create_proc_lang(), CreateCast(), CreateFunction(), CreateRole(), CreateSchemaCommand(), CreateStatistics(), CreateTransform(), DefineCollation(), DefineDomain(), DefineIndex(), DefineOpClass(), DefineTSConfiguration(), DefineType(), DeleteRelationTuple(), DeleteSequenceTuple(), DelRoleMems(), deparseOpExpr(), deparseScalarArrayOpExpr(), do_autovacuum(), do_compile(), do_setval(), dropdb(), DropProceduralLanguageById(), DropRole(), DropSubscription(), enum_cmp_internal(), enum_in(), enum_out(), enum_recv(), enum_send(), errdatatype(), eval_const_expressions_mutator(), examine_simple_variable(), examine_variable(), ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), ExecHashBuildSkewHash(), ExecInitAgg(), ExecuteDoStmt(), expand_all_col_privileges(), fetch_agg_sort_op(), fetch_fp_info(), find_coercion_pathway(), find_typmod_coercion_function(), fixup_whole_row_references(), flatten_reloptions(), fmgr_c_validator(), fmgr_info_cxt_security(), fmgr_info_other_lang(), fmgr_internal_validator(), fmgr_security_definer(), fmgr_sql_validator(), format_operator_internal(), format_operator_parts(), format_procedure_internal(), format_procedure_parts(), format_type_internal(), func_get_detail(), func_parallel(), func_strict(), func_volatile(), FuncNameAsType(), FunctionIsVisible(), generate_collation_name(), generate_function_name(), generate_operator_name(), generate_partition_qual(), generate_qualified_relation_name(), generate_relation_name(), generateClonedIndexStmt(), get_agg_clause_costs_walker(), get_am_name(), get_am_type_oid(), get_array_type(), get_attavgwidth(), get_attidentity(), get_attname(), get_attnum(), get_attribute_options(), get_attstatsslot(), get_atttype(), get_atttypetypmodcoll(), get_atttypmod(), get_base_element_type(), get_collation(), get_collation_name(), get_commutator(), get_constraint_name(), get_database_name(), get_db_info(), get_default_acl_internal(), get_element_type(), get_func_cost(), get_func_leakproof(), get_func_name(), get_func_namespace(), get_func_nargs(), get_func_result_name(), get_func_retset(), get_func_rettype(), get_func_rows(), get_func_signature(), get_func_variadictype(), get_language_name(), get_namespace_name(), get_negator(), get_object_address_defacl(), get_object_address_opf_member(), get_object_address_type(), get_object_address_usermapping(), get_object_namespace(), get_op_opfamily_properties(), get_op_opfamily_sortfamily(), get_op_opfamily_strategy(), get_op_rettype(), get_opclass(), get_opclass_family(), get_opclass_input_type(), get_opclass_name(), get_opclass_oid(), get_opcode(), get_oper_expr(), get_opfamily_member(), get_opfamily_oid(), get_opfamily_proc(), get_opname(), get_oprjoin(), get_oprrest(), get_publication_name(), get_range_subtype(), get_rel_name(), get_rel_namespace(), get_rel_oids(), get_rel_persistence(), get_rel_relkind(), get_rel_tablespace(), get_rel_type_id(), get_relation_statistics(), get_rewrite_oid(), get_role_password(), get_rolespec_name(), get_rte_attribute_is_dropped(), get_rte_attribute_type(), get_subscription_name(), get_tablespace(), get_transform_fromsql(), get_transform_tosql(), get_typ_typrelid(), get_typbyval(), get_typcollation(), get_typdefault(), get_type_category_preferred(), get_type_io_data(), get_typisdefined(), get_typlen(), get_typlenbyval(), get_typlenbyvalalign(), get_typmodin(), get_typstorage(), get_typtype(), getBaseTypeAndTypmod(), GetFdwRoutineByServerId(), GetForeignColumnOptions(), GetForeignDataWrapper(), GetForeignServer(), GetForeignServerIdByRelId(), GetForeignTable(), GetIndexAmRoutineByAmId(), getObjectDescription(), getObjectIdentityParts(), getOpFamilyDescription(), getOpFamilyIdentity(), getProcedureTypeDescription(), GetPublication(), getRelationDescription(), getRelationIdentity(), GetRelationPublicationActions(), getRelationTypeDescription(), GetSubscription(), GetSubscriptionRelState(), GetSysCacheOid(), getTypeBinaryInputInfo(), getTypeBinaryOutputInfo(), getTypeInputInfo(), getTypeOutputInfo(), GetUserMapping(), GetUserNameFromId(), ginvalidate(), gistproperty(), gistvalidate(), has_bypassrls_privilege(), has_createrole_privilege(), has_rolinherit(), has_rolreplication(), has_subclass(), hash_ok_operator(), hashvalidate(), have_createdb_privilege(), heap_drop_with_catalog(), inclusion_get_strategy_procinfo(), index_check_primary_key(), index_drop(), indexam_property(), IndexGetRelation(), IndexSupportsBackwardScan(), init_sql_fcache(), initialize_peragg(), InitializeSessionUserId(), inline_set_returning_function(), InsertRule(), internal_get_result_type(), interpret_function_parameter_list(), IsBinaryCoercible(), load_domaintype_info(), load_rangetype_info(), logicalrep_write_tuple(), logicalrep_write_typ(), lookup_collation_cache(), lookup_ts_config_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupAggWithArgs(), LookupTypeNameOid(), make_new_heap(), make_op(), make_scalar_array_op(), map_sql_table_to_xmlschema(), map_sql_type_to_xml_name(), mark_index_clustered(), minmax_get_strategy_procinfo(), mv_GenerateOper(), nextval_internal(), op_hashjoinable(), op_input_types(), op_mergejoinable(), OpclassIsVisible(), OperatorGet(), OperatorIsVisible(), OpernameGetOprid(), OpfamilyIsVisible(), ParseFuncOrColumn(), parseTypeString(), pg_attribute_aclcheck_all(), pg_attribute_aclmask(), pg_class_aclmask(), pg_class_ownercheck(), pg_collation_actual_version(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_aclmask(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_foreign_data_wrapper_aclmask(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_aclmask(), pg_foreign_server_ownercheck(), pg_get_function_arg_default(), pg_get_function_arguments(), pg_get_function_identity_arguments(), pg_get_function_result(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_statisticsext_worker(), pg_get_userbyid(), pg_language_aclmask(), pg_language_ownercheck(), pg_namespace_aclmask(), pg_namespace_ownercheck(), pg_newlocale_from_collation(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_aclmask(), pg_proc_ownercheck(), pg_publication_ownercheck(), pg_relation_filenode(), pg_relation_filepath(), pg_sequence_parameters(), pg_statistics_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_aclmask(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_aclmask(), pg_type_ownercheck(), plperl_validator(), plpgsql_build_datatype(), plpgsql_compile(), plpgsql_parse_cwordtype(), plpgsql_parse_wordtype(), plpgsql_validator(), plpython_validator(), PLy_input_tuple_funcs(), PLy_output_tuple_funcs(), PLy_procedure_argument_valid(), PLy_procedure_create(), PLy_procedure_get(), PLy_spi_prepare(), PLyString_ToComposite(), prepare_column_cache(), print_function_arguments(), ProcedureCreate(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameAttribute(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), recomputeNamespacePath(), recordExtObjInitPriv(), regclassout(), regconfigout(), regdictionaryout(), regoperout(), regprocout(), regtypeout(), relation_mark_replica_identity(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), RelationCacheInitializePhase3(), relationHasPrimaryKey(), RelationHasUnloggedIndex(), RelationInitIndexAccessInfo(), RelationIsVisible(), RelationReloadIndexInfo(), RemoveAccessMethodById(), RemoveConstraintById(), RemoveEventTriggerById(), removeExtObjInitPriv(), RemoveForeignDataWrapperById(), RemoveForeignServerById(), RemoveFunctionById(), RemoveObjects(), RemoveOpClassById(), RemoveOperatorById(), RemoveOpFamilyById(), RemovePartitionKeyByRelId(), RemovePublicationById(), RemovePublicationRelById(), RemoveSchemaById(), RemoveStatisticsById(), RemoveTSConfigurationById(), RemoveTSDictionaryById(), RemoveTSParserById(), RemoveTSTemplateById(), RemoveTypeById(), RemoveUserMappingById(), rename_constraint_internal(), RenameConstraint(), RenameRole(), replorigin_by_name(), replorigin_by_oid(), replorigin_drop(), ResetSequence(), ResolveOpClass(), ri_add_cast_to(), ri_GenerateQual(), ri_GenerateQualCollation(), ri_LoadConstraintInfo(), SearchSysCacheAttName(), SearchSysCacheCopy(), SearchSysCacheCopyAttName(), SearchSysCacheExists(), SearchSysCacheExistsAttName(), sepgsql_proc_setattr(), sepgsql_relation_setattr(), sequence_options(), SetDefaultACL(), simplify_function(), spgvalidate(), SPI_gettype(), staext_dependencies_load(), statext_ndistinct_load(), statext_store(), superuser_arg(), test_indoption(), transformArrayType(), transformColumnDefinition(), transformColumnNameList(), transformColumnType(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), transformOfType(), triggered_change_notification(), TryReuseForeignKey(), TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), TupleDescInitEntry(), typeidTypeRelid(), typeIsOfTypedTable(), TypeIsVisible(), typenameTypeId(), typenameTypeIdAndMod(), update_attstats(), and verify_dictoptions().

1117 {
1118  ReleaseCatCache(tuple);
1119 }
void ReleaseCatCache(HeapTuple tuple)
Definition: catcache.c:1317
HeapTuple SearchSysCache ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 1098 of file syscache.c.

References elog, ERROR, PointerIsValid, SearchCatCache(), and SysCacheSize.

Referenced by GetSysCacheOid(), SearchSysCacheCopy(), and SearchSysCacheExists().

1103 {
1104  if (cacheId < 0 || cacheId >= SysCacheSize ||
1105  !PointerIsValid(SysCache[cacheId]))
1106  elog(ERROR, "invalid cache ID: %d", cacheId);
1107 
1108  return SearchCatCache(SysCache[cacheId], key1, key2, key3, key4);
1109 }
#define ERROR
Definition: elog.h:43
#define SysCacheSize
Definition: syscache.c:974
static CatCache * SysCache[SysCacheSize]
Definition: syscache.c:976
HeapTuple SearchCatCache(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
Definition: catcache.c:1103
#define elog
Definition: elog.h:219
#define PointerIsValid(pointer)
Definition: c.h:526
HeapTuple SearchSysCacheAttName ( Oid  relid,
const char *  attname 
)

Definition at line 1204 of file syscache.c.

References ATTNAME, CStringGetDatum, GETSTRUCT, HeapTupleIsValid, NULL, ObjectIdGetDatum, ReleaseSysCache(), and SearchSysCache2.

Referenced by ATExecAlterColumnGenericOptions(), ATExecDropColumn(), ATExecSetOptions(), ATPrepAlterColumnType(), ComputeIndexAttrs(), ComputePartitionAttrs(), CreateStatistics(), get_attnum(), plpgsql_parse_cwordtype(), SearchSysCacheCopyAttName(), SearchSysCacheExistsAttName(), and transformColumnNameList().

1205 {
1206  HeapTuple tuple;
1207 
1208  tuple = SearchSysCache2(ATTNAME,
1209  ObjectIdGetDatum(relid),
1210  CStringGetDatum(attname));
1211  if (!HeapTupleIsValid(tuple))
1212  return NULL;
1213  if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
1214  {
1215  ReleaseSysCache(tuple);
1216  return NULL;
1217  }
1218  return tuple;
1219 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define CStringGetDatum(X)
Definition: postgres.h:584
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:187
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define SearchSysCache2(cacheId, key1, key2)
Definition: syscache.h:154
HeapTuple SearchSysCacheCopy ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 1130 of file syscache.c.

References heap_copytuple(), HeapTupleIsValid, ReleaseSysCache(), and SearchSysCache().

1135 {
1136  HeapTuple tuple,
1137  newtuple;
1138 
1139  tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
1140  if (!HeapTupleIsValid(tuple))
1141  return tuple;
1142  newtuple = heap_copytuple(tuple);
1143  ReleaseSysCache(tuple);
1144  return newtuple;
1145 }
HeapTuple SearchSysCache(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1098
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
HeapTuple SearchSysCacheCopyAttName ( Oid  relid,
const char *  attname 
)

Definition at line 1227 of file syscache.c.

References heap_copytuple(), HeapTupleIsValid, ReleaseSysCache(), and SearchSysCacheAttName().

Referenced by ATExecAddColumn(), ATExecAddIdentity(), ATExecAlterColumnType(), ATExecDropColumn(), ATExecDropIdentity(), ATExecDropNotNull(), ATExecSetIdentity(), ATExecSetNotNull(), ATExecSetStatistics(), ATExecSetStorage(), MergeAttributesIntoExisting(), and renameatt_internal().

1228 {
1229  HeapTuple tuple,
1230  newtuple;
1231 
1232  tuple = SearchSysCacheAttName(relid, attname);
1233  if (!HeapTupleIsValid(tuple))
1234  return tuple;
1235  newtuple = heap_copytuple(tuple);
1236  ReleaseSysCache(tuple);
1237  return newtuple;
1238 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:1204
bool SearchSysCacheExists ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 1154 of file syscache.c.

References HeapTupleIsValid, ReleaseSysCache(), and SearchSysCache().

1159 {
1160  HeapTuple tuple;
1161 
1162  tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
1163  if (!HeapTupleIsValid(tuple))
1164  return false;
1165  ReleaseSysCache(tuple);
1166  return true;
1167 }
HeapTuple SearchSysCache(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1098
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
bool SearchSysCacheExistsAttName ( Oid  relid,
const char *  attname 
)

Definition at line 1246 of file syscache.c.

References HeapTupleIsValid, ReleaseSysCache(), and SearchSysCacheAttName().

Referenced by RemoveInheritance().

1247 {
1248  HeapTuple tuple;
1249 
1250  tuple = SearchSysCacheAttName(relid, attname);
1251  if (!HeapTupleIsValid(tuple))
1252  return false;
1253  ReleaseSysCache(tuple);
1254  return true;
1255 }
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1116
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:1204
struct catclist* SearchSysCacheList ( int  cacheId,
int  nkeys,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 1330 of file syscache.c.

References elog, ERROR, PointerIsValid, SearchCatCacheList(), and SysCacheSize.

1332 {
1333  if (cacheId < 0 || cacheId >= SysCacheSize ||
1334  !PointerIsValid(SysCache[cacheId]))
1335  elog(ERROR, "invalid cache ID: %d", cacheId);
1336 
1337  return SearchCatCacheList(SysCache[cacheId], nkeys,
1338  key1, key2, key3, key4);
1339 }
#define ERROR
Definition: elog.h:43
#define SysCacheSize
Definition: syscache.c:974
static CatCache * SysCache[SysCacheSize]
Definition: syscache.c:976
CatCList * SearchCatCacheList(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3, Datum v4)
Definition: catcache.c:1389
#define elog
Definition: elog.h:219
#define PointerIsValid(pointer)
Definition: c.h:526
Datum SysCacheGetAttr ( int  cacheId,
HeapTuple  tup,
AttrNumber  attributeNumber,
bool isNull 
)

Definition at line 1278 of file syscache.c.

References Assert, elog, ERROR, heap_getattr, InitCatCachePhase2(), PointerIsValid, and SysCacheSize.

Referenced by AlterCollation(), AlterDomainValidateConstraint(), AlterForeignDataWrapper(), AlterForeignServer(), AlterFunction(), AlterRole(), AlterSchemaOwner_internal(), AlterTSDictionary(), AlterUserMapping(), ATExecAlterColumnGenericOptions(), ATExecChangeOwner(), ATExecDetachPartition(), ATExecGenericOptions(), ATExecSetOptions(), ATExecSetRelOptions(), build_function_result_tupdesc_t(), build_replindex_scan_key(), CheckIndexCompatible(), compile_plperl_function(), compile_pltcl_function(), DefineDomain(), do_compile(), DropSubscription(), ExecGrant_Attribute(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecInitAgg(), fetch_function_defaults(), fetch_statentries_for_relation(), flatten_reloptions(), fmgr_c_validator(), fmgr_info_C_lang(), fmgr_info_cxt_security(), fmgr_internal_validator(), fmgr_security_definer(), fmgr_sql_validator(), func_get_detail(), generate_partition_qual(), generateClonedIndexStmt(), get_attribute_options(), get_attstatsslot(), get_default_acl_internal(), get_func_arg_info(), get_func_result_name(), get_func_trftypes(), get_object_namespace(), get_role_password(), get_tablespace(), get_typdefault(), GetForeignColumnOptions(), GetForeignDataWrapper(), GetForeignServer(), GetForeignTable(), GetSubscription(), GetSubscriptionRelState(), GetUserMapping(), gistproperty(), inclusion_get_strategy_procinfo(), init_sql_fcache(), initialize_peragg(), inline_function(), inline_set_returning_function(), lookup_ts_dictionary_cache(), make_new_heap(), MatchNamedCall(), minmax_get_strategy_procinfo(), pg_attribute_aclmask(), pg_class_aclmask(), pg_database_aclmask(), pg_foreign_data_wrapper_aclmask(), pg_foreign_server_aclmask(), pg_get_constraintdef_worker(), pg_get_function_arg_default(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_statisticsext_worker(), pg_language_aclmask(), pg_namespace_aclmask(), pg_newlocale_from_collation(), pg_proc_aclmask(), pg_tablespace_aclmask(), pg_type_aclmask(), PLy_procedure_create(), prepare_sql_fn_parse_info(), print_function_arguments(), ProcedureCreate(), recordExtObjInitPriv(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), ri_LoadConstraintInfo(), SetDefaultACL(), staext_dependencies_load(), statext_ndistinct_load(), StorePartitionBound(), test_indoption(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), transformIndexConstraint(), TryReuseForeignKey(), and validateCheckConstraint().

1281 {
1282  /*
1283  * We just need to get the TupleDesc out of the cache entry, and then we
1284  * can apply heap_getattr(). Normally the cache control data is already
1285  * valid (because the caller recently fetched the tuple via this same
1286  * cache), but there are cases where we have to initialize the cache here.
1287  */
1288  if (cacheId < 0 || cacheId >= SysCacheSize ||
1289  !PointerIsValid(SysCache[cacheId]))
1290  elog(ERROR, "invalid cache ID: %d", cacheId);
1291  if (!PointerIsValid(SysCache[cacheId]->cc_tupdesc))
1292  {
1293  InitCatCachePhase2(SysCache[cacheId], false);
1294  Assert(PointerIsValid(SysCache[cacheId]->cc_tupdesc));
1295  }
1296 
1297  return heap_getattr(tup, attributeNumber,
1298  SysCache[cacheId]->cc_tupdesc,
1299  isNull);
1300 }
#define ERROR
Definition: elog.h:43
#define SysCacheSize
Definition: syscache.c:974
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:769
static CatCache * SysCache[SysCacheSize]
Definition: syscache.c:976
#define Assert(condition)
Definition: c.h:675
#define elog
Definition: elog.h:219
void InitCatCachePhase2(CatCache *cache, bool touch_index)
Definition: catcache.c:988
#define PointerIsValid(pointer)
Definition: c.h:526

Variable Documentation

const struct cachedesc cacheinfo[]
static

Definition at line 123 of file syscache.c.

bool CacheInitialized = false
static

Definition at line 978 of file syscache.c.

Referenced by InitCatalogCache(), and InitCatalogCachePhase2().

CatCache* SysCache[SysCacheSize]
static

Definition at line 976 of file syscache.c.

Oid SysCacheRelationOid[SysCacheSize]
static

Definition at line 981 of file syscache.c.

Referenced by InitCatalogCache(), and RelationHasSysCache().

int SysCacheRelationOidSize
static

Definition at line 982 of file syscache.c.

Referenced by InitCatalogCache(), and RelationHasSysCache().

Oid SysCacheSupportingRelOid[SysCacheSize *2]
static

Definition at line 985 of file syscache.c.

Referenced by InitCatalogCache(), and RelationSupportsSysCache().

int SysCacheSupportingRelOidSize
static

Definition at line 986 of file syscache.c.

Referenced by InitCatalogCache(), and RelationSupportsSysCache().