PostgreSQL Source Code git master
syscache.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "catalog/pg_db_role_setting_d.h"
#include "catalog/pg_depend_d.h"
#include "catalog/pg_description_d.h"
#include "catalog/pg_seclabel_d.h"
#include "catalog/pg_shdepend_d.h"
#include "catalog/pg_shdescription_d.h"
#include "catalog/pg_shseclabel_d.h"
#include "common/int.h"
#include "lib/qunique.h"
#include "miscadmin.h"
#include "storage/lmgr.h"
#include "utils/catcache.h"
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
#include "catalog/syscache_info.h"
Include dependency graph for syscache.c:

Go to the source code of this file.

Data Structures

struct  cachedesc
 

Macros

#define KEY(...)   VA_ARGS_NARGS(__VA_ARGS__), { __VA_ARGS__ }
 

Functions

 StaticAssertDecl (lengthof(cacheinfo)==SysCacheSize, "SysCacheSize does not match syscache.c's array")
 
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)
 
HeapTuple SearchSysCache1 (int cacheId, Datum key1)
 
HeapTuple SearchSysCache2 (int cacheId, Datum key1, Datum key2)
 
HeapTuple SearchSysCache3 (int cacheId, Datum key1, Datum key2, Datum key3)
 
HeapTuple SearchSysCache4 (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
void ReleaseSysCache (HeapTuple tuple)
 
HeapTuple SearchSysCacheLocked1 (int cacheId, Datum key1)
 
HeapTuple SearchSysCacheCopy (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
HeapTuple SearchSysCacheLockedCopy1 (int cacheId, Datum key1)
 
bool SearchSysCacheExists (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
Oid GetSysCacheOid (int cacheId, AttrNumber oidcol, 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)
 
HeapTuple SearchSysCacheAttNum (Oid relid, int16 attnum)
 
HeapTuple SearchSysCacheCopyAttNum (Oid relid, int16 attnum)
 
Datum SysCacheGetAttr (int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
 
Datum SysCacheGetAttrNotNull (int cacheId, HeapTuple tup, AttrNumber attributeNumber)
 
uint32 GetSysCacheHashValue (int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
 
struct catclistSearchSysCacheList (int cacheId, int nkeys, Datum key1, Datum key2, Datum key3)
 
void SysCacheInvalidate (int cacheId, uint32 hashValue)
 
bool RelationInvalidatesSnapshotsOnly (Oid relid)
 
bool RelationHasSysCache (Oid relid)
 
bool RelationSupportsSysCache (Oid relid)
 

Variables

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

◆ KEY

#define KEY (   ...)    VA_ARGS_NARGS(__VA_ARGS__), { __VA_ARGS__ }

Definition at line 79 of file syscache.c.

Function Documentation

◆ GetSysCacheHashValue()

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

Definition at line 661 of file syscache.c.

666{
667 if (cacheId < 0 || cacheId >= SysCacheSize ||
668 !PointerIsValid(SysCache[cacheId]))
669 elog(ERROR, "invalid cache ID: %d", cacheId);
670
671 return GetCatCacheHashValue(SysCache[cacheId], key1, key2, key3, key4);
672}
#define PointerIsValid(pointer)
Definition: c.h:720
uint32 GetCatCacheHashValue(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
Definition: catcache.c:1662
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
static CatCache * SysCache[SysCacheSize]
Definition: syscache.c:86

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

◆ GetSysCacheOid()

Oid GetSysCacheOid ( int  cacheId,
AttrNumber  oidcol,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 448 of file syscache.c.

454{
455 HeapTuple tuple;
456 bool isNull;
457 Oid result;
458
459 tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
460 if (!HeapTupleIsValid(tuple))
461 return InvalidOid;
462 result = heap_getattr(tuple, oidcol,
463 SysCache[cacheId]->cc_tupdesc,
464 &isNull);
465 Assert(!isNull); /* columns used as oids should never be NULL */
466 ReleaseSysCache(tuple);
467 return result;
468}
#define Assert(condition)
Definition: c.h:815
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:903
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:269
HeapTuple SearchSysCache(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:208

References Assert, heap_getattr(), HeapTupleIsValid, InvalidOid, ReleaseSysCache(), SearchSysCache(), and SysCache.

◆ InitCatalogCache()

void InitCatalogCache ( void  )

Definition at line 110 of file syscache.c.

111{
112 int cacheId;
113
115
117
118 for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
119 {
120 /*
121 * Assert that every enumeration value defined in syscache.h has been
122 * populated in the cacheinfo array.
123 */
124 Assert(OidIsValid(cacheinfo[cacheId].reloid));
125 Assert(OidIsValid(cacheinfo[cacheId].indoid));
126 /* .nbuckets and .key[] are checked by InitCatCache() */
127
128 SysCache[cacheId] = InitCatCache(cacheId,
129 cacheinfo[cacheId].reloid,
130 cacheinfo[cacheId].indoid,
131 cacheinfo[cacheId].nkeys,
132 cacheinfo[cacheId].key,
133 cacheinfo[cacheId].nbuckets);
134 if (!PointerIsValid(SysCache[cacheId]))
135 elog(ERROR, "could not initialize cache %u (%d)",
136 cacheinfo[cacheId].reloid, cacheId);
137 /* Accumulate data for OID lists, too */
139 cacheinfo[cacheId].reloid;
141 cacheinfo[cacheId].reloid;
143 cacheinfo[cacheId].indoid;
144 /* see comments for RelationInvalidatesSnapshotsOnly */
145 Assert(!RelationInvalidatesSnapshotsOnly(cacheinfo[cacheId].reloid));
146 }
147
150
151 /* Sort and de-dup OID arrays, so we can use binary search. */
153 sizeof(Oid), oid_compare);
157
159 sizeof(Oid), oid_compare);
162 sizeof(Oid), oid_compare);
163
164 CacheInitialized = true;
165}
#define lengthof(array)
Definition: c.h:745
#define OidIsValid(objectId)
Definition: c.h:732
CatCache * InitCatCache(int id, Oid reloid, Oid indexoid, int nkeys, const int *key, int nbuckets)
Definition: catcache.c:878
#define qsort(a, b, c, d)
Definition: port.h:474
static size_t qunique(void *array, size_t elements, size_t width, int(*compare)(const void *, const void *))
Definition: qunique.h:21
static bool CacheInitialized
Definition: syscache.c:88
static int oid_compare(const void *a, const void *b)
Definition: syscache.c:795
static int SysCacheSupportingRelOidSize
Definition: syscache.c:96
static Oid SysCacheRelationOid[SysCacheSize]
Definition: syscache.c:91
static Oid SysCacheSupportingRelOid[SysCacheSize *2]
Definition: syscache.c:95
static int SysCacheRelationOidSize
Definition: syscache.c:92
bool RelationInvalidatesSnapshotsOnly(Oid relid)
Definition: syscache.c:722

References Assert, CacheInitialized, elog, ERROR, InitCatCache(), sort-test::key, lengthof, oid_compare(), OidIsValid, PointerIsValid, qsort, qunique(), RelationInvalidatesSnapshotsOnly(), SysCache, SysCacheRelationOid, SysCacheRelationOidSize, SysCacheSupportingRelOid, and SysCacheSupportingRelOidSize.

Referenced by InitPostgres().

◆ InitCatalogCachePhase2()

void InitCatalogCachePhase2 ( void  )

Definition at line 180 of file syscache.c.

181{
182 int cacheId;
183
185
186 for (cacheId = 0; cacheId < SysCacheSize; cacheId++)
187 InitCatCachePhase2(SysCache[cacheId], true);
188}
void InitCatCachePhase2(CatCache *cache, bool touch_index)
Definition: catcache.c:1195

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

Referenced by RelationCacheInitializePhase3().

◆ oid_compare()

static int oid_compare ( const void *  a,
const void *  b 
)
static

Definition at line 795 of file syscache.c.

796{
797 Oid oa = *((const Oid *) a);
798 Oid ob = *((const Oid *) b);
799
800 return pg_cmp_u32(oa, ob);
801}
static int pg_cmp_u32(uint32 a, uint32 b)
Definition: int.h:652
int b
Definition: isn.c:69
int a
Definition: isn.c:68

References a, b, and pg_cmp_u32().

Referenced by InitCatalogCache().

◆ RelationHasSysCache()

bool RelationHasSysCache ( Oid  relid)

Definition at line 745 of file syscache.c.

746{
747 int low = 0,
748 high = SysCacheRelationOidSize - 1;
749
750 while (low <= high)
751 {
752 int middle = low + (high - low) / 2;
753
754 if (SysCacheRelationOid[middle] == relid)
755 return true;
756 if (SysCacheRelationOid[middle] < relid)
757 low = middle + 1;
758 else
759 high = middle - 1;
760 }
761
762 return false;
763}

References SysCacheRelationOid, and SysCacheRelationOidSize.

Referenced by GetNonHistoricCatalogSnapshot().

◆ RelationInvalidatesSnapshotsOnly()

bool RelationInvalidatesSnapshotsOnly ( Oid  relid)

Definition at line 722 of file syscache.c.

723{
724 switch (relid)
725 {
726 case DbRoleSettingRelationId:
727 case DependRelationId:
728 case SharedDependRelationId:
729 case DescriptionRelationId:
730 case SharedDescriptionRelationId:
731 case SecLabelRelationId:
732 case SharedSecLabelRelationId:
733 return true;
734 default:
735 break;
736 }
737
738 return false;
739}

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

◆ RelationSupportsSysCache()

bool RelationSupportsSysCache ( Oid  relid)

Definition at line 770 of file syscache.c.

771{
772 int low = 0,
774
775 while (low <= high)
776 {
777 int middle = low + (high - low) / 2;
778
779 if (SysCacheSupportingRelOid[middle] == relid)
780 return true;
781 if (SysCacheSupportingRelOid[middle] < relid)
782 low = middle + 1;
783 else
784 high = middle - 1;
785 }
786
787 return false;
788}

References SysCacheSupportingRelOid, and SysCacheSupportingRelOidSize.

Referenced by RelationIdIsInInitFile().

◆ ReleaseSysCache()

void ReleaseSysCache ( HeapTuple  tuple)

Definition at line 269 of file syscache.c.

270{
271 ReleaseCatCache(tuple);
272}
void ReleaseCatCache(HeapTuple tuple)
Definition: catcache.c:1623

References ReleaseCatCache().

Referenced by aclitemout(), add_cast_to(), add_function_cost(), AddEnumLabel(), AddRoleMems(), agg_args_support_sendreceive(), AggregateCreate(), AlterDomainValidateConstraint(), AlterEnum(), AlterObjectRename_internal(), AlterOpFamily(), AlterPublicationOptions(), AlterPublicationSchemas(), AlterPublicationTables(), AlterRole(), AlterRoleSet(), AlterSchemaOwner(), AlterSchemaOwner_oid(), AlterStatistics(), AlterTSConfiguration(), AlterTSDictionary(), AlterType(), AlterTypeOwner(), AlterTypeOwner_oid(), AlterTypeRecurse(), amvalidate(), appendFunctionName(), appendOrderBySuffix(), assignOperTypes(), assignProcTypes(), ATAddForeignKeyConstraint(), ATDetachCheckNoForeignKeyRefs(), ATExecAddOf(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecAlterConstraint(), ATExecChangeOwner(), ATExecDropColumn(), ATExecSetExpression(), ATExecSetOptions(), ATExecSetRelOptions(), ATExecSetStatistics(), ATPostAlterTypeCleanup(), ATPrepAddPrimaryKey(), ATPrepAlterColumnType(), attribute_statistics_update(), blvalidate(), brincostestimate(), brinvalidate(), btcostestimate(), btvalidate(), build_coercion_expression(), CacheInvalidateRelcacheByRelid(), call_pltcl_start_proc(), CallStmtResultDesc(), check_amop_signature(), check_amproc_signature(), check_and_fetch_column_list(), check_default_text_search_config(), check_enable_rls(), check_for_column_name_collision(), check_object_ownership(), check_role(), check_session_authorization(), CheckFunctionValidatorAccess(), CheckIndexCompatible(), CheckMyDatabase(), CloneFkReferenced(), CloneFkReferencing(), coerce_type(), CollationIsVisibleExt(), compatible_oper(), compatible_oper_opid(), compile_plperl_function(), compile_pltcl_function(), compute_return_type(), ComputeIndexAttrs(), ComputePartitionAttrs(), ConstraintSetParentConstraint(), ConstructTupleDescriptor(), ConversionIsVisibleExt(), convert_column_name(), create_pg_locale(), create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), CreateCast(), CreateFunction(), CreateProceduralLanguage(), CreateRole(), CreateSchemaCommand(), CreateStatistics(), CreateTransform(), database_is_invalid_oid(), DefineCollation(), DefineDomain(), DefineIndex(), DefineOpClass(), DefineTSConfiguration(), DefineType(), delete_pg_statistic(), DeleteRelationTuple(), DeleteSequenceTuple(), deparseOpExpr(), deparseScalarArrayOpExpr(), DetachPartitionFinalize(), do_autovacuum(), do_compile(), do_setval(), DropObjectById(), DropRole(), DropSubscription(), enum_cmp_internal(), enum_in(), enum_out(), enum_recv(), enum_send(), errdatatype(), eval_const_expressions_mutator(), examine_attribute(), examine_simple_variable(), examine_variable(), ExecGrant_Attribute(), ExecGrant_common(), ExecGrant_Parameter(), ExecGrant_Relation(), ExecHashBuildSkewHash(), ExecInitAgg(), ExecuteCallStmt(), ExecuteDoStmt(), expand_all_col_privileges(), expand_vacuum_rel(), fetch_agg_sort_op(), fetch_fp_info(), fillTypeDesc(), 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(), fmgr_symbol(), format_operator_extended(), format_operator_parts(), format_procedure_extended(), format_procedure_parts(), format_type_extended(), func_get_detail(), func_parallel(), func_strict(), func_volatile(), FuncNameAsType(), FunctionIsVisibleExt(), generate_collation_name(), generate_function_name(), generate_operator_clause(), generate_operator_name(), generate_partition_qual(), generate_qualified_relation_name(), generate_qualified_type_name(), generate_relation_name(), generateClonedExtStatsStmt(), generateClonedIndexStmt(), get_am_name(), get_am_type_oid(), get_array_type(), get_attavgwidth(), get_attgenerated(), get_attname(), get_attnum(), get_attoptions(), get_attr_stat_type(), get_attribute_options(), get_attstatsslot(), get_atttype(), get_atttypetypmodcoll(), get_base_element_type(), get_collation(), get_collation_isdeterministic(), get_collation_name(), get_commutator(), get_constraint_index(), get_constraint_name(), get_constraint_type(), get_database_name(), get_db_info(), get_default_acl_internal(), get_default_partition_oid(), get_element_type(), get_extension_name(), get_extension_schema(), get_func_leakproof(), get_func_name(), get_func_namespace(), get_func_nargs(), get_func_prokind(), get_func_result_name(), get_func_retset(), get_func_rettype(), get_func_signature(), get_func_support(), get_func_variadictype(), get_function_rows(), get_index_column_opclass(), get_index_isclustered(), get_index_isreplident(), get_index_isvalid(), get_language_name(), get_multirange_range(), 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_method(), get_opclass_name(), get_opclass_oid(), get_opclass_opfamily_and_input_type(), get_opcode(), get_opfamily_member(), get_opfamily_oid(), get_opfamily_proc(), get_opname(), get_oprjoin(), get_oprrest(), get_publication_name(), get_qual_for_range(), get_range_collation(), get_range_multirange(), get_range_subtype(), get_rel_name(), get_rel_namespace(), get_rel_persistence(), get_rel_relam(), get_rel_relispartition(), get_rel_relkind(), get_rel_tablespace(), get_rel_type_id(), get_relation_statistics(), get_relation_statistics_worker(), get_rewrite_oid(), get_ri_constraint_root(), get_role_password(), get_rolespec_name(), get_rte_attribute_is_dropped(), 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_typsubscript(), get_typtype(), getBaseTypeAndTypmod(), GetFdwRoutineByServerId(), GetForeignColumnOptions(), GetForeignDataWrapperExtended(), GetForeignServerExtended(), GetForeignServerIdByRelId(), GetForeignTable(), GetIndexAmRoutineByAmId(), getObjectDescription(), getObjectIdentityParts(), getOpFamilyDescription(), getOpFamilyIdentity(), getProcedureTypeDescription(), GetPublication(), getPublicationSchemaInfo(), getRelationDescription(), getRelationIdentity(), getRelationTypeDescription(), GetSubscription(), GetSubscriptionRelState(), GetSysCacheOid(), getTypeBinaryInputInfo(), getTypeBinaryOutputInfo(), getTypeInputInfo(), getTypeOutputInfo(), GetUserMapping(), GetUserNameFromId(), ginvalidate(), gistvalidate(), has_bypassrls_privilege(), has_createrole_privilege(), has_rolreplication(), has_subclass(), hash_ok_operator(), hashvalidate(), have_createdb_privilege(), heap_drop_with_catalog(), inclusion_get_strategy_procinfo(), index_check_primary_key(), index_concurrently_create_copy(), index_create(), index_drop(), index_get_partition(), indexam_property(), IndexGetRelation(), IndexSupportsBackwardScan(), init_database_collation(), init_sql_fcache(), initialize_peragg(), InitializeSessionUserId(), inline_set_returning_function(), InsertRule(), internal_get_result_type(), interpret_function_parameter_list(), IsBinaryCoercibleWithCast(), load_domaintype_info(), load_rangetype_info(), logicalrep_write_tuple(), logicalrep_write_typ(), lookup_collation(), lookup_ts_config_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupTypeNameOid(), make_callstmt_target(), make_inh_translation_list(), make_new_heap(), make_op(), make_scalar_array_op(), map_sql_table_to_xmlschema(), map_sql_type_to_xml_name(), minmax_get_strategy_procinfo(), minmax_multi_get_strategy_procinfo(), nextval_internal(), object_aclmask_ext(), object_ownercheck(), op_hashjoinable(), op_input_types(), op_mergejoinable(), OpclassIsVisibleExt(), OperatorGet(), OperatorIsVisibleExt(), OpernameGetOprid(), OpfamilyIsVisibleExt(), ParseFuncOrColumn(), parseTypeString(), pg_attribute_aclcheck_all_ext(), pg_attribute_aclmask_ext(), pg_basetype(), pg_class_aclmask_ext(), pg_collation_actual_version(), pg_database_collation_actual_version(), pg_get_constraintdef_worker(), pg_get_function_arg_default(), pg_get_function_arguments(), pg_get_function_identity_arguments(), pg_get_function_result(), pg_get_function_sqlbody(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_statisticsobj_worker(), pg_get_statisticsobjdef_expressions(), pg_get_userbyid(), pg_namespace_aclmask_ext(), pg_nextoid(), pg_parameter_acl_aclmask(), pg_parameter_aclmask(), pg_relation_filenode(), pg_relation_filepath(), pg_relation_is_publishable(), pg_sequence_parameters(), pg_type_aclmask_ext(), pgoutput_row_filter_init(), plperl_validator(), plpgsql_build_datatype(), plpgsql_compile(), plpgsql_parse_cwordtype(), plpgsql_validator(), plpython3_validator(), plsample_func_handler(), plsample_trigger_handler(), PLy_procedure_create(), PLy_procedure_get(), postgres_fdw_get_connections_internal(), prepare_column_cache(), preprocess_aggref(), preprocessNamespacePath(), print_function_arguments(), ProcedureCreate(), pub_rf_contains_invalid_column(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForAttachIndex(), RangeVarCallbackForDropRelation(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameAttribute(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackForTruncate(), RangeVarCallbackOwnsRelation(), recordExtObjInitPriv(), refresh_by_match_merge(), regclassout(), regcollationout(), regconfigout(), regdictionaryout(), regoperout(), regprocout(), regtypeout(), relation_statistics_update(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), RelationBuildPublicationDesc(), RelationCacheInitializePhase3(), RelationClearMissing(), relationHasPrimaryKey(), RelationInitIndexAccessInfo(), RelationInitTableAccessMethod(), RelationIsVisibleExt(), RelationReloadIndexInfo(), RemoveConstraintById(), removeExtObjInitPriv(), RemoveFunctionById(), RemoveOperatorById(), RemovePartitionKeyByRelId(), RemovePublicationById(), RemovePublicationRelById(), RemovePublicationSchemaById(), RemoveRoleFromInitPriv(), RemoveRoleFromObjectPolicy(), RemoveStatisticsById(), RemoveStatisticsDataById(), RemoveTSConfigurationById(), RemoveTypeById(), rename_constraint_internal(), RenameConstraint(), RenameRole(), replorigin_by_name(), replorigin_by_oid(), replorigin_drop_by_name(), ResetSequence(), ResolveOpClass(), ri_GenerateQualCollation(), ri_LoadConstraintInfo(), roles_is_member_of(), SearchSysCacheAttName(), SearchSysCacheAttNum(), SearchSysCacheCopy(), SearchSysCacheCopyAttName(), SearchSysCacheCopyAttNum(), SearchSysCacheExists(), SearchSysCacheExistsAttName(), SearchSysCacheLocked1(), SearchSysCacheLockedCopy1(), sepgsql_proc_setattr(), sepgsql_relation_setattr(), sequence_options(), SetAttrMissing(), SetDefaultACL(), simplify_function(), spgvalidate(), SPI_gettype(), statext_dependencies_load(), statext_expressions_load(), statext_mcv_load(), statext_ndistinct_load(), StatisticsGetRelation(), StatisticsObjIsVisibleExt(), superuser_arg(), transformCallStmt(), transformColumnDefinition(), transformColumnNameList(), transformColumnType(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), transformOfType(), triggered_change_notification(), tryAttachPartitionForeignKey(), TryReuseForeignKey(), TSConfigIsVisibleExt(), TSDictionaryIsVisibleExt(), TSParserIsVisibleExt(), TSTemplateIsVisibleExt(), TupleDescInitEntry(), typeidTypeRelid(), typeIsOfTypedTable(), TypeIsVisibleExt(), typenameTypeId(), typenameTypeIdAndMod(), typeOrDomainTypeRelid(), update_attstats(), validatePartitionedIndex(), and verify_dictoptions().

◆ SearchSysCache()

HeapTuple SearchSysCache ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 208 of file syscache.c.

213{
214 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
215 PointerIsValid(SysCache[cacheId]));
216
217 return SearchCatCache(SysCache[cacheId], key1, key2, key3, key4);
218}
HeapTuple SearchCatCache(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
Definition: catcache.c:1312

References Assert, PointerIsValid, SearchCatCache(), and SysCache.

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

◆ SearchSysCache1()

HeapTuple SearchSysCache1 ( int  cacheId,
Datum  key1 
)

Definition at line 221 of file syscache.c.

223{
224 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
225 PointerIsValid(SysCache[cacheId]));
226 Assert(SysCache[cacheId]->cc_nkeys == 1);
227
228 return SearchCatCache1(SysCache[cacheId], key1);
229}
HeapTuple SearchCatCache1(CatCache *cache, Datum v1)
Definition: catcache.c:1329

References Assert, PointerIsValid, SearchCatCache1(), and SysCache.

Referenced by aclitemout(), add_cast_to(), add_function_cost(), AddRoleMems(), agg_args_support_sendreceive(), AggregateCreate(), AlterDomainValidateConstraint(), AlterEnum(), AlterObjectRename_internal(), AlterOpFamily(), AlterSchemaOwner(), AlterSchemaOwner_oid(), AlterStatistics(), AlterTSDictionary(), AlterTypeOwner_oid(), AlterTypeRecurse(), amvalidate(), appendFunctionName(), appendOrderBySuffix(), assignOperTypes(), assignProcTypes(), ATAddForeignKeyConstraint(), ATDetachCheckNoForeignKeyRefs(), ATExecAlterColumnGenericOptions(), ATExecAlterConstraint(), ATExecChangeOwner(), ATExecSetRelOptions(), ATPostAlterTypeCleanup(), blvalidate(), brinvalidate(), btvalidate(), build_coercion_expression(), CacheInvalidateRelcacheByRelid(), call_pltcl_start_proc(), CallStmtResultDesc(), check_amop_signature(), check_amproc_signature(), check_default_text_search_config(), check_enable_rls(), check_object_ownership(), check_role(), check_session_authorization(), CheckFunctionValidatorAccess(), CheckIndexCompatible(), CheckMyDatabase(), CloneFkReferenced(), CloneFkReferencing(), CollationIsVisibleExt(), compile_plperl_function(), compile_pltcl_function(), ComputeIndexAttrs(), ConstraintSetParentConstraint(), ConstructTupleDescriptor(), ConversionIsVisibleExt(), create_pg_locale(), create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), CreateCast(), CreateEventTrigger(), CreateFunction(), CreateProceduralLanguage(), CreateSchemaCommand(), CreateTransform(), database_is_invalid_oid(), DefineCollation(), DefineIndex(), DefineOpClass(), DefineTSConfiguration(), DeleteRelationTuple(), DeleteSequenceTuple(), deparseOpExpr(), deparseScalarArrayOpExpr(), DetachPartitionFinalize(), do_autovacuum(), do_compile(), do_setval(), DropObjectById(), DropRole(), enum_cmp_internal(), enum_out(), enum_send(), errdatatype(), eval_const_expressions_mutator(), ExecGrant_Parameter(), ExecInitAgg(), ExecuteCallStmt(), ExecuteDoStmt(), expand_vacuum_rel(), fetch_agg_sort_op(), fetch_fp_info(), fillTypeDesc(), 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(), fmgr_symbol(), format_operator_extended(), format_operator_parts(), format_procedure_extended(), format_procedure_parts(), format_type_extended(), func_get_detail(), func_parallel(), func_strict(), func_volatile(), FunctionIsVisibleExt(), generate_collation_name(), generate_function_name(), generate_operator_clause(), generate_operator_name(), generate_partition_qual(), generate_qualified_relation_name(), generate_qualified_type_name(), generate_relation_name(), generateClonedExtStatsStmt(), generateClonedIndexStmt(), get_am_name(), get_am_type_oid(), get_array_type(), get_attstatsslot(), get_base_element_type(), get_collation(), get_collation_isdeterministic(), get_collation_name(), get_commutator(), get_constraint_index(), get_constraint_name(), get_constraint_type(), get_database_name(), get_db_info(), get_default_partition_oid(), get_element_type(), get_extension_name(), get_extension_schema(), get_func_leakproof(), get_func_name(), get_func_namespace(), get_func_nargs(), get_func_prokind(), get_func_result_name(), get_func_retset(), get_func_rettype(), get_func_signature(), get_func_support(), get_func_variadictype(), get_function_rows(), get_index_column_opclass(), get_index_isclustered(), get_index_isreplident(), get_index_isvalid(), get_language_name(), get_multirange_range(), get_namespace_name(), get_negator(), get_object_address_defacl(), get_object_address_usermapping(), get_object_namespace(), get_op_rettype(), get_opclass(), get_opclass_family(), get_opclass_input_type(), get_opclass_method(), get_opclass_name(), get_opclass_opfamily_and_input_type(), get_opcode(), get_opname(), get_oprjoin(), get_oprrest(), get_publication_name(), get_qual_for_range(), get_range_collation(), get_range_multirange(), get_range_subtype(), get_rel_name(), get_rel_namespace(), get_rel_persistence(), get_rel_relam(), get_rel_relispartition(), get_rel_relkind(), get_rel_tablespace(), get_rel_type_id(), get_relation_statistics(), get_ri_constraint_root(), get_role_password(), get_rolespec_tuple(), get_subscription_name(), get_tablespace(), 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_typsubscript(), get_typtype(), getBaseTypeAndTypmod(), GetFdwRoutineByServerId(), GetForeignDataWrapperExtended(), GetForeignServerExtended(), GetForeignServerIdByRelId(), GetForeignTable(), GetIndexAmRoutineByAmId(), getObjectDescription(), getObjectIdentityParts(), GetOperatorFromCompareType(), getOpFamilyDescription(), getOpFamilyIdentity(), getProcedureTypeDescription(), GetPublication(), getPublicationSchemaInfo(), getRelationDescription(), getRelationIdentity(), getRelationTypeDescription(), GetSubscription(), GetTSConfigTuple(), getTypeBinaryInputInfo(), getTypeBinaryOutputInfo(), getTypeInputInfo(), getTypeOutputInfo(), GetUserNameFromId(), ginvalidate(), gistvalidate(), has_bypassrls_privilege(), has_createrole_privilege(), has_rolreplication(), has_subclass(), hash_ok_operator(), hashvalidate(), have_createdb_privilege(), heap_drop_with_catalog(), index_concurrently_create_copy(), index_create(), index_drop(), index_get_partition(), indexam_property(), IndexGetRelation(), IndexSupportsBackwardScan(), init_database_collation(), init_sql_fcache(), initialize_peragg(), InitializeSessionUserId(), inline_set_returning_function(), internal_get_result_type(), left_oper(), load_domaintype_info(), load_rangetype_info(), logicalrep_write_tuple(), logicalrep_write_typ(), lookup_ts_config_cache(), lookup_ts_dictionary_cache(), lookup_ts_parser_cache(), lookup_type_cache(), LookupTypeNameExtended(), make_callstmt_target(), make_new_heap(), map_sql_table_to_xmlschema(), map_sql_type_to_xml_name(), nextval_internal(), object_aclmask_ext(), object_ownercheck(), op_hashjoinable(), op_input_types(), op_mergejoinable(), OpClassCacheLookup(), OpclassIsVisibleExt(), oper(), OperatorIsVisibleExt(), OpFamilyCacheLookup(), OpfamilyIsVisibleExt(), ParseFuncOrColumn(), pg_attribute_aclcheck_all_ext(), pg_attribute_aclmask_ext(), pg_basetype(), pg_class_aclmask_ext(), pg_collation_actual_version(), pg_database_collation_actual_version(), pg_get_constraintdef_worker(), pg_get_function_arg_default(), pg_get_function_arguments(), pg_get_function_identity_arguments(), pg_get_function_result(), pg_get_function_sqlbody(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_statisticsobj_worker(), pg_get_statisticsobjdef_expressions(), pg_get_userbyid(), pg_namespace_aclmask_ext(), pg_parameter_acl_aclmask(), pg_parameter_aclmask(), pg_relation_filenode(), pg_relation_filepath(), pg_relation_is_publishable(), pg_sequence_parameters(), pg_type_aclmask_ext(), plperl_validator(), plpgsql_build_datatype(), plpgsql_compile(), plpgsql_parse_cwordtype(), plpgsql_validator(), plpython3_validator(), plsample_func_handler(), plsample_trigger_handler(), PLy_procedure_create(), PLy_procedure_get(), postgres_fdw_get_connections_internal(), prepare_column_cache(), preprocess_aggref(), preprocessNamespacePath(), print_function_arguments(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForAttachIndex(), RangeVarCallbackForDropRelation(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameAttribute(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackForTruncate(), RangeVarCallbackOwnsRelation(), recordExtObjInitPriv(), refresh_by_match_merge(), regclassout(), regcollationout(), regconfigout(), regdictionaryout(), regoperout(), regprocout(), regtypeout(), relation_statistics_update(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), RelationBuildPublicationDesc(), RelationCacheInitializePhase3(), relationHasPrimaryKey(), RelationInitIndexAccessInfo(), RelationInitTableAccessMethod(), RelationIsVisibleExt(), RelationReloadIndexInfo(), RemoveConstraintById(), removeExtObjInitPriv(), RemoveFunctionById(), RemoveOperatorById(), RemovePartitionKeyByRelId(), RemovePublicationById(), RemovePublicationRelById(), RemovePublicationSchemaById(), RemoveRoleFromInitPriv(), RemoveRoleFromObjectPolicy(), RemoveStatisticsById(), RemoveTSConfigurationById(), RemoveTypeById(), rename_constraint_internal(), RenameConstraint(), RenameRole(), replorigin_by_name(), replorigin_by_oid(), replorigin_drop_by_name(), ResetSequence(), ResolveOpClass(), ri_GenerateQualCollation(), ri_LoadConstraintInfo(), roles_is_member_of(), SearchSysCacheLocked1(), sepgsql_proc_setattr(), sepgsql_relation_setattr(), sequence_options(), simplify_function(), spgvalidate(), SPI_gettype(), StatisticsGetRelation(), StatisticsObjIsVisibleExt(), superuser_arg(), transformCallStmt(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), triggered_change_notification(), tryAttachPartitionForeignKey(), TryReuseForeignKey(), TSConfigIsVisibleExt(), TSDictionaryIsVisibleExt(), TSParserIsVisibleExt(), TSTemplateIsVisibleExt(), TupleDescInitEntry(), typeidType(), typeidTypeRelid(), typeIsOfTypedTable(), TypeIsVisibleExt(), typeOrDomainTypeRelid(), validatePartitionedIndex(), and verify_dictoptions().

◆ SearchSysCache2()

HeapTuple SearchSysCache2 ( int  cacheId,
Datum  key1,
Datum  key2 
)

Definition at line 232 of file syscache.c.

234{
235 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
236 PointerIsValid(SysCache[cacheId]));
237 Assert(SysCache[cacheId]->cc_nkeys == 2);
238
239 return SearchCatCache2(SysCache[cacheId], key1, key2);
240}
HeapTuple SearchCatCache2(CatCache *cache, Datum v1, Datum v2)
Definition: catcache.c:1337

References Assert, PointerIsValid, SearchCatCache2(), and SysCache.

Referenced by AddEnumLabel(), AlterPublicationOptions(), AlterPublicationSchemas(), AlterPublicationTables(), CastCreate(), check_and_fetch_column_list(), check_for_column_name_collision(), convert_column_name(), CreateTransform(), DropSubscription(), enum_in(), enum_recv(), examine_attribute(), ExecGrant_Attribute(), expand_all_col_privileges(), find_coercion_pathway(), find_typmod_coercion_function(), fixup_whole_row_references(), get_attgenerated(), get_attname(), get_attoptions(), get_attr_stat_type(), get_attribute_options(), get_atttype(), get_atttypetypmodcoll(), get_object_address_usermapping(), get_relation_statistics_worker(), get_rewrite_oid(), get_rte_attribute_is_dropped(), get_transform_fromsql(), get_transform_tosql(), GetForeignColumnOptions(), GetSubscriptionRelState(), GetUserMapping(), index_check_primary_key(), index_concurrently_create_copy(), InsertRule(), IsBinaryCoercibleWithCast(), pg_attribute_aclcheck_all_ext(), pg_attribute_aclmask_ext(), pgoutput_row_filter_init(), pub_rf_contains_invalid_column(), recordExtObjInitPriv(), RelationClearMissing(), removeExtObjInitPriv(), RemoveStatisticsDataById(), SearchSysCacheAttName(), SearchSysCacheAttNum(), statext_dependencies_load(), statext_expressions_load(), statext_mcv_load(), and statext_ndistinct_load().

◆ SearchSysCache3()

◆ SearchSysCache4()

HeapTuple SearchSysCache4 ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 254 of file syscache.c.

256{
257 Assert(cacheId >= 0 && cacheId < SysCacheSize &&
258 PointerIsValid(SysCache[cacheId]));
259 Assert(SysCache[cacheId]->cc_nkeys == 4);
260
261 return SearchCatCache4(SysCache[cacheId], key1, key2, key3, key4);
262}
HeapTuple SearchCatCache4(CatCache *cache, Datum v1, Datum v2, Datum v3, Datum v4)
Definition: catcache.c:1353

References Assert, PointerIsValid, SearchCatCache4(), and SysCache.

Referenced by get_object_address_opf_member(), get_opfamily_member(), get_opfamily_proc(), inclusion_get_strategy_procinfo(), minmax_get_strategy_procinfo(), minmax_multi_get_strategy_procinfo(), OperatorGet(), and OpernameGetOprid().

◆ SearchSysCacheAttName()

HeapTuple SearchSysCacheAttName ( Oid  relid,
const char *  attname 
)

Definition at line 480 of file syscache.c.

481{
482 HeapTuple tuple;
483
484 tuple = SearchSysCache2(ATTNAME,
485 ObjectIdGetDatum(relid),
487 if (!HeapTupleIsValid(tuple))
488 return NULL;
489 if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
490 {
491 ReleaseSysCache(tuple);
492 return NULL;
493 }
494 return tuple;
495}
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
NameData attname
Definition: pg_attribute.h:41
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:200
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:257
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:355
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:232

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

Referenced by ATExecAlterColumnGenericOptions(), ATExecDropColumn(), ATExecSetExpression(), ATExecSetOptions(), ATExecSetStatistics(), ATPrepAddPrimaryKey(), ATPrepAlterColumnType(), ComputeIndexAttrs(), ComputePartitionAttrs(), CreateStatistics(), get_attnum(), make_inh_translation_list(), pg_nextoid(), plpgsql_parse_cwordtype(), SearchSysCacheCopyAttName(), SearchSysCacheExistsAttName(), SetAttrMissing(), and transformColumnNameList().

◆ SearchSysCacheAttNum()

HeapTuple SearchSysCacheAttNum ( Oid  relid,
int16  attnum 
)

Definition at line 543 of file syscache.c.

544{
545 HeapTuple tuple;
546
547 tuple = SearchSysCache2(ATTNUM,
548 ObjectIdGetDatum(relid),
550 if (!HeapTupleIsValid(tuple))
551 return NULL;
552 if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
553 {
554 ReleaseSysCache(tuple);
555 return NULL;
556 }
557 return tuple;
558}
int16 attnum
Definition: pg_attribute.h:74
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:177

References attnum, GETSTRUCT(), HeapTupleIsValid, Int16GetDatum(), ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache2().

Referenced by ATExecSetStatistics(), and SearchSysCacheCopyAttNum().

◆ SearchSysCacheCopy()

HeapTuple SearchSysCacheCopy ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 379 of file syscache.c.

384{
385 HeapTuple tuple,
386 newtuple;
387
388 tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
389 if (!HeapTupleIsValid(tuple))
390 return tuple;
391 newtuple = heap_copytuple(tuple);
392 ReleaseSysCache(tuple);
393 return newtuple;
394}
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:778

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

◆ SearchSysCacheCopyAttName()

HeapTuple SearchSysCacheCopyAttName ( Oid  relid,
const char *  attname 
)

Definition at line 503 of file syscache.c.

504{
505 HeapTuple tuple,
506 newtuple;
507
508 tuple = SearchSysCacheAttName(relid, attname);
509 if (!HeapTupleIsValid(tuple))
510 return tuple;
511 newtuple = heap_copytuple(tuple);
512 ReleaseSysCache(tuple);
513 return newtuple;
514}
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:480

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

Referenced by ATExecAddColumn(), ATExecAddIdentity(), ATExecAlterColumnType(), ATExecDropColumn(), ATExecDropExpression(), ATExecDropIdentity(), ATExecDropNotNull(), ATExecSetCompression(), ATExecSetIdentity(), ATExecSetStorage(), ATPrepDropExpression(), MergeAttributesIntoExisting(), and renameatt_internal().

◆ SearchSysCacheCopyAttNum()

HeapTuple SearchSysCacheCopyAttNum ( Oid  relid,
int16  attnum 
)

Definition at line 566 of file syscache.c.

567{
568 HeapTuple tuple,
569 newtuple;
570
571 tuple = SearchSysCacheAttNum(relid, attnum);
572 if (!HeapTupleIsValid(tuple))
573 return NULL;
574 newtuple = heap_copytuple(tuple);
575 ReleaseSysCache(tuple);
576 return newtuple;
577}
HeapTuple SearchSysCacheAttNum(Oid relid, int16 attnum)
Definition: syscache.c:543

References attnum, heap_copytuple(), HeapTupleIsValid, ReleaseSysCache(), and SearchSysCacheAttNum().

Referenced by dropconstraint_internal(), pg_get_acl(), set_attnotnull(), and SetIndexStorageProperties().

◆ SearchSysCacheExists()

bool SearchSysCacheExists ( int  cacheId,
Datum  key1,
Datum  key2,
Datum  key3,
Datum  key4 
)

Definition at line 425 of file syscache.c.

430{
431 HeapTuple tuple;
432
433 tuple = SearchSysCache(cacheId, key1, key2, key3, key4);
434 if (!HeapTupleIsValid(tuple))
435 return false;
436 ReleaseSysCache(tuple);
437 return true;
438}

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

◆ SearchSysCacheExistsAttName()

bool SearchSysCacheExistsAttName ( Oid  relid,
const char *  attname 
)

Definition at line 522 of file syscache.c.

523{
524 HeapTuple tuple;
525
526 tuple = SearchSysCacheAttName(relid, attname);
527 if (!HeapTupleIsValid(tuple))
528 return false;
529 ReleaseSysCache(tuple);
530 return true;
531}

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

Referenced by RemoveInheritance().

◆ SearchSysCacheList()

struct catclist * SearchSysCacheList ( int  cacheId,
int  nkeys,
Datum  key1,
Datum  key2,
Datum  key3 
)

Definition at line 678 of file syscache.c.

680{
681 if (cacheId < 0 || cacheId >= SysCacheSize ||
682 !PointerIsValid(SysCache[cacheId]))
683 elog(ERROR, "invalid cache ID: %d", cacheId);
684
685 return SearchCatCacheList(SysCache[cacheId], nkeys,
686 key1, key2, key3);
687}
CatCList * SearchCatCacheList(CatCache *cache, int nkeys, Datum v1, Datum v2, Datum v3)
Definition: catcache.c:1696

References elog, ERROR, catclist::nkeys, PointerIsValid, SearchCatCacheList(), and SysCache.

◆ SearchSysCacheLocked1()

HeapTuple SearchSysCacheLocked1 ( int  cacheId,
Datum  key1 
)

Definition at line 287 of file syscache.c.

289{
290 CatCache *cache = SysCache[cacheId];
291 ItemPointerData tid;
292 LOCKTAG tag;
293
294 /*----------
295 * Since inplace updates may happen just before our LockTuple(), we must
296 * return content acquired after LockTuple() of the TID we return. If we
297 * just fetched twice instead of looping, the following sequence would
298 * defeat our locking:
299 *
300 * GRANT: SearchSysCache1() = TID (1,5)
301 * GRANT: LockTuple(pg_class, (1,5))
302 * [no more inplace update of (1,5) until we release the lock]
303 * CLUSTER: SearchSysCache1() = TID (1,5)
304 * CLUSTER: heap_update() = TID (1,8)
305 * CLUSTER: COMMIT
306 * GRANT: SearchSysCache1() = TID (1,8)
307 * GRANT: return (1,8) from SearchSysCacheLocked1()
308 * VACUUM: SearchSysCache1() = TID (1,8)
309 * VACUUM: LockTuple(pg_class, (1,8)) # two TIDs now locked for one rel
310 * VACUUM: inplace update
311 * GRANT: heap_update() = (1,9) # lose inplace update
312 *
313 * In the happy case, this takes two fetches, one to determine the TID to
314 * lock and another to get the content and confirm the TID didn't change.
315 *
316 * This is valid even if the row gets updated to a new TID, the old TID
317 * becomes LP_UNUSED, and the row gets updated back to its old TID. We'd
318 * still hold the right LOCKTAG_TUPLE and a copy of the row captured after
319 * the LOCKTAG_TUPLE.
320 */
322 for (;;)
323 {
324 HeapTuple tuple;
326
327 tuple = SearchSysCache1(cacheId, key1);
328 if (ItemPointerIsValid(&tid))
329 {
330 if (!HeapTupleIsValid(tuple))
331 {
332 LockRelease(&tag, lockmode, false);
333 return tuple;
334 }
335 if (ItemPointerEquals(&tid, &tuple->t_self))
336 return tuple;
337 LockRelease(&tag, lockmode, false);
338 }
339 else if (!HeapTupleIsValid(tuple))
340 return tuple;
341
342 tid = tuple->t_self;
343 ReleaseSysCache(tuple);
344
345 /*
346 * Do like LockTuple(rel, &tid, lockmode). While cc_relisshared won't
347 * change from one iteration to another, it may have been a temporary
348 * "false" until our first SearchSysCache1().
349 */
352 cache->cc_reloid,
355 (void) LockAcquire(&tag, lockmode, false, false);
356
357 /*
358 * If an inplace update just finished, ensure we process the syscache
359 * inval.
360 *
361 * If a heap_update() call just released its LOCKTAG_TUPLE, we'll
362 * probably find the old tuple and reach "tuple concurrently updated".
363 * If that heap_update() aborts, our LOCKTAG_TUPLE blocks inplace
364 * updates while our caller works.
365 */
367 }
368}
Oid MyDatabaseId
Definition: globals.c:93
void AcceptInvalidationMessages(void)
Definition: inval.c:863
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
Definition: itemptr.c:35
static void ItemPointerSetInvalid(ItemPointerData *pointer)
Definition: itemptr.h:184
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
Definition: itemptr.h:124
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
static bool ItemPointerIsValid(const ItemPointerData *pointer)
Definition: itemptr.h:83
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:803
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:2011
#define SET_LOCKTAG_TUPLE(locktag, dboid, reloid, blocknum, offnum)
Definition: lock.h:217
int LOCKMODE
Definition: lockdefs.h:26
#define InplaceUpdateTupleLock
Definition: lockdefs.h:48
ItemPointerData t_self
Definition: htup.h:65
Definition: lock.h:165
Oid cc_reloid
Definition: catcache.h:60
bool cc_relisshared
Definition: catcache.h:62
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:221

References AcceptInvalidationMessages(), catcache::cc_relisshared, catcache::cc_reloid, HeapTupleIsValid, InplaceUpdateTupleLock, InvalidOid, ItemPointerEquals(), ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), ItemPointerIsValid(), ItemPointerSetInvalid(), LockAcquire(), LockRelease(), MyDatabaseId, ReleaseSysCache(), SearchSysCache1(), SET_LOCKTAG_TUPLE, SysCache, and HeapTupleData::t_self.

Referenced by ATExecSetRelOptions(), ExecGrant_common(), ExecGrant_Relation(), and SearchSysCacheLockedCopy1().

◆ SearchSysCacheLockedCopy1()

HeapTuple SearchSysCacheLockedCopy1 ( int  cacheId,
Datum  key1 
)

Definition at line 404 of file syscache.c.

406{
407 HeapTuple tuple,
408 newtuple;
409
410 tuple = SearchSysCacheLocked1(cacheId, key1);
411 if (!HeapTupleIsValid(tuple))
412 return tuple;
413 newtuple = heap_copytuple(tuple);
414 ReleaseSysCache(tuple);
415 return newtuple;
416}
HeapTuple SearchSysCacheLocked1(int cacheId, Datum key1)
Definition: syscache.c:287

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

Referenced by AlterRelationNamespaceInternal(), get_catalog_object_by_oid_extended(), RelationSetNewRelfilenumber(), RenameDatabase(), RenameRelationInternal(), SetDatabaseHasLoginEventTriggers(), SetRelationTableSpace(), and update_relispartition().

◆ StaticAssertDecl()

StaticAssertDecl ( lengthof(cacheinfo)  = =SysCacheSize,
"SysCacheSize does not match syscache.c's array"   
)

◆ SysCacheGetAttr()

Datum SysCacheGetAttr ( int  cacheId,
HeapTuple  tup,
AttrNumber  attributeNumber,
bool *  isNull 
)

Definition at line 600 of file syscache.c.

603{
604 /*
605 * We just need to get the TupleDesc out of the cache entry, and then we
606 * can apply heap_getattr(). Normally the cache control data is already
607 * valid (because the caller recently fetched the tuple via this same
608 * cache), but there are cases where we have to initialize the cache here.
609 */
610 if (cacheId < 0 || cacheId >= SysCacheSize ||
611 !PointerIsValid(SysCache[cacheId]))
612 elog(ERROR, "invalid cache ID: %d", cacheId);
613 if (!PointerIsValid(SysCache[cacheId]->cc_tupdesc))
614 {
615 InitCatCachePhase2(SysCache[cacheId], false);
616 Assert(PointerIsValid(SysCache[cacheId]->cc_tupdesc));
617 }
618
619 return heap_getattr(tup, attributeNumber,
620 SysCache[cacheId]->cc_tupdesc,
621 isNull);
622}

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

Referenced by AlterCollation(), AlterForeignDataWrapper(), AlterForeignServer(), AlterFunction(), AlterPublicationTables(), AlterRole(), AlterSchemaOwner_internal(), AlterTSDictionary(), AlterUserMapping(), ATExecAlterColumnGenericOptions(), ATExecChangeOwner(), ATExecGenericOptions(), ATExecSetOptions(), ATExecSetRelOptions(), build_function_result_tupdesc_t(), check_and_fetch_column_list(), CheckMyDatabase(), compile_plperl_function(), create_pg_locale(), create_pg_locale_icu(), DeconstructFkConstraintRow(), DefineCollation(), DefineDomain(), DropSubscription(), examine_attribute(), ExecGrant_Attribute(), ExecGrant_common(), ExecGrant_Parameter(), ExecGrant_Relation(), ExecInitAgg(), expand_function_arguments(), fetch_statentries_for_relation(), flatten_reloptions(), fmgr_security_definer(), fmgr_sql_validator(), FuncnameGetCandidates(), generate_partition_qual(), generateClonedExtStatsStmt(), generateClonedIndexStmt(), get_attoptions(), get_attribute_options(), get_db_info(), get_default_acl_internal(), get_func_arg_info(), get_func_trftypes(), get_relation_statistics(), get_role_password(), get_tablespace(), get_typdefault(), GetForeignColumnOptions(), GetForeignDataWrapperExtended(), GetForeignServerExtended(), GetForeignTable(), GetSubscription(), GetSubscriptionRelations(), GetSubscriptionRelState(), GetUserMapping(), index_concurrently_create_copy(), init_sql_fcache(), initialize_peragg(), inline_function(), inline_set_returning_function(), lookup_ts_dictionary_cache(), make_new_heap(), MatchNamedCall(), object_aclmask_ext(), pg_attribute_aclcheck_all_ext(), pg_attribute_aclmask_ext(), pg_class_aclmask_ext(), pg_get_acl(), pg_get_constraintdef_worker(), pg_get_function_arg_default(), pg_get_function_sqlbody(), pg_get_functiondef(), pg_get_publication_tables(), pg_namespace_aclmask_ext(), pg_parameter_acl_aclmask(), pg_parameter_aclmask(), pg_type_aclmask_ext(), pgoutput_row_filter_init(), plsample_func_handler(), plsample_trigger_handler(), PLy_procedure_create(), prepare_sql_fn_parse_info(), preprocess_aggref(), print_function_arguments(), ProcedureCreate(), pub_rf_contains_invalid_column(), recordExtObjInitPriv(), RelationBuildPartitionDesc(), RelationBuildPartitionKey(), SetDefaultACL(), statext_dependencies_load(), statext_expressions_load(), statext_mcv_load(), statext_ndistinct_load(), StorePartitionBound(), SysCacheGetAttrNotNull(), and transformCallStmt().

◆ SysCacheGetAttrNotNull()

Datum SysCacheGetAttrNotNull ( int  cacheId,
HeapTuple  tup,
AttrNumber  attributeNumber 
)

Definition at line 631 of file syscache.c.

633{
634 bool isnull;
635 Datum attr;
636
637 attr = SysCacheGetAttr(cacheId, tup, attributeNumber, &isnull);
638
639 if (isnull)
640 {
641 elog(ERROR,
642 "unexpected null value in cached tuple for catalog %s column %s",
643 get_rel_name(cacheinfo[cacheId].reloid),
644 NameStr(TupleDescAttr(SysCache[cacheId]->cc_tupdesc, attributeNumber - 1)->attname));
645 }
646
647 return attr;
648}
#define NameStr(name)
Definition: c.h:703
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1928
uintptr_t Datum
Definition: postgres.h:69
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:600
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:153

References attname, elog, ERROR, get_rel_name(), NameStr, SysCache, SysCacheGetAttr(), and TupleDescAttr().

Referenced by AlterCollation(), AlterDomainValidateConstraint(), build_function_result_tupdesc_t(), build_replindex_scan_key(), CheckIndexCompatible(), CheckMyDatabase(), compile_plperl_function(), compile_pltcl_function(), create_pg_locale(), create_pg_locale_builtin(), create_pg_locale_icu(), create_pg_locale_libc(), DeconstructFkConstraintRow(), do_compile(), DropSubscription(), ExecGrant_common(), ExecGrant_Parameter(), extractNotNullColumn(), fetch_function_defaults(), fetch_statentries_for_relation(), fmgr_c_validator(), fmgr_info_C_lang(), fmgr_info_cxt_security(), fmgr_internal_validator(), fmgr_sql_validator(), fmgr_symbol(), func_get_detail(), generateClonedExtStatsStmt(), generateClonedIndexStmt(), get_attstatsslot(), get_db_info(), get_func_result_name(), get_index_column_opclass(), get_object_namespace(), get_qual_for_range(), getObjectDescription(), getObjectIdentityParts(), GetSubscription(), inclusion_get_strategy_procinfo(), index_concurrently_create_copy(), index_opclass_options(), init_sql_fcache(), inline_function(), inline_set_returning_function(), IsIndexUsableForReplicaIdentityFull(), minmax_get_strategy_procinfo(), minmax_multi_get_strategy_procinfo(), object_aclmask_ext(), object_ownercheck(), pg_collation_actual_version(), pg_database_collation_actual_version(), pg_get_constraintdef_worker(), pg_get_functiondef(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), pg_get_statisticsobj_worker(), pg_get_statisticsobjdef_expressions(), PLy_procedure_create(), print_function_sqlbody(), ProcedureCreate(), QueueCheckConstraintValidation(), refresh_by_match_merge(), RelationBuildPartitionKey(), RemoveRoleFromInitPriv(), test_indoption(), transformFkeyCheckAttrs(), transformFkeyGetPrimaryKey(), transformIndexConstraint(), and TryReuseForeignKey().

◆ SysCacheInvalidate()

void SysCacheInvalidate ( int  cacheId,
uint32  hashValue 
)

Definition at line 698 of file syscache.c.

699{
700 if (cacheId < 0 || cacheId >= SysCacheSize)
701 elog(ERROR, "invalid cache ID: %d", cacheId);
702
703 /* if this cache isn't initialized yet, no need to do anything */
704 if (!PointerIsValid(SysCache[cacheId]))
705 return;
706
707 CatCacheInvalidate(SysCache[cacheId], hashValue);
708}
void CatCacheInvalidate(CatCache *cache, uint32 hashValue)
Definition: catcache.c:625

References CatCacheInvalidate(), elog, ERROR, PointerIsValid, and SysCache.

Referenced by LocalExecuteInvalidationMessage().

Variable Documentation

◆ CacheInitialized

bool CacheInitialized = false
static

Definition at line 88 of file syscache.c.

Referenced by InitCatalogCache(), and InitCatalogCachePhase2().

◆ SysCache

◆ SysCacheRelationOid

Oid SysCacheRelationOid[SysCacheSize]
static

Definition at line 91 of file syscache.c.

Referenced by InitCatalogCache(), and RelationHasSysCache().

◆ SysCacheRelationOidSize

int SysCacheRelationOidSize
static

Definition at line 92 of file syscache.c.

Referenced by InitCatalogCache(), and RelationHasSysCache().

◆ SysCacheSupportingRelOid

Oid SysCacheSupportingRelOid[SysCacheSize *2]
static

Definition at line 95 of file syscache.c.

Referenced by InitCatalogCache(), and RelationSupportsSysCache().

◆ SysCacheSupportingRelOidSize

int SysCacheSupportingRelOidSize
static

Definition at line 96 of file syscache.c.

Referenced by InitCatalogCache(), and RelationSupportsSysCache().