PostgreSQL Source Code  git master
indexing.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "catalog/index.h"
#include "catalog/indexing.h"
#include "executor/executor.h"
#include "utils/rel.h"
Include dependency graph for indexing.c:

Go to the source code of this file.

Functions

CatalogIndexState CatalogOpenIndexes (Relation heapRel)
 
void CatalogCloseIndexes (CatalogIndexState indstate)
 
static void CatalogIndexInsert (CatalogIndexState indstate, HeapTuple heapTuple)
 
void CatalogTupleInsert (Relation heapRel, HeapTuple tup)
 
void CatalogTupleInsertWithInfo (Relation heapRel, HeapTuple tup, CatalogIndexState indstate)
 
void CatalogTupleUpdate (Relation heapRel, ItemPointer otid, HeapTuple tup)
 
void CatalogTupleUpdateWithInfo (Relation heapRel, ItemPointer otid, HeapTuple tup, CatalogIndexState indstate)
 
void CatalogTupleDelete (Relation heapRel, ItemPointer tid)
 

Function Documentation

◆ CatalogCloseIndexes()

void CatalogCloseIndexes ( CatalogIndexState  indstate)

Definition at line 60 of file indexing.c.

References ExecCloseIndices(), and pfree().

Referenced by AddNewAttributeTuples(), AppendAttributeTuples(), CatalogTupleInsert(), CatalogTupleUpdate(), copyTemplateDependencies(), inv_truncate(), inv_write(), recordMultipleDependencies(), and swap_relation_files().

61 {
62  ExecCloseIndices(indstate);
63  pfree(indstate);
64 }
void pfree(void *pointer)
Definition: mcxt.c:1031
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
Definition: execIndexing.c:226

◆ CatalogIndexInsert()

static void CatalogIndexInsert ( CatalogIndexState  indstate,
HeapTuple  heapTuple 
)
static

Definition at line 74 of file indexing.c.

References Assert, ExecDropSingleTupleTableSlot(), ExecStoreHeapTuple(), FormIndexDatum(), HeapTupleIsHeapOnly, i, IndexInfo::ii_ExclusionOps, IndexInfo::ii_Expressions, IndexInfo::ii_NumIndexKeyAttrs, IndexInfo::ii_Predicate, IndexInfo::ii_ReadyForInserts, index_insert(), INDEX_MAX_KEYS, MakeSingleTupleTableSlot(), NIL, RelationData::rd_index, ReindexIsProcessingIndex(), RelationGetDescr, RelationGetRelid, ResultRelInfo::ri_IndexRelationDescs, ResultRelInfo::ri_IndexRelationInfo, ResultRelInfo::ri_NumIndices, ResultRelInfo::ri_RelationDesc, HeapTupleData::t_self, TTSOpsHeapTuple, UNIQUE_CHECK_NO, UNIQUE_CHECK_YES, and values.

Referenced by CatalogTupleInsert(), CatalogTupleInsertWithInfo(), CatalogTupleUpdate(), and CatalogTupleUpdateWithInfo().

75 {
76  int i;
77  int numIndexes;
78  RelationPtr relationDescs;
79  Relation heapRelation;
80  TupleTableSlot *slot;
81  IndexInfo **indexInfoArray;
83  bool isnull[INDEX_MAX_KEYS];
84 
85  /*
86  * HOT update does not require index inserts. But with asserts enabled we
87  * want to check that it'd be legal to currently insert into the
88  * table/index.
89  */
90 #ifndef USE_ASSERT_CHECKING
91  if (HeapTupleIsHeapOnly(heapTuple))
92  return;
93 #endif
94 
95  /*
96  * Get information from the state structure. Fall out if nothing to do.
97  */
98  numIndexes = indstate->ri_NumIndices;
99  if (numIndexes == 0)
100  return;
101  relationDescs = indstate->ri_IndexRelationDescs;
102  indexInfoArray = indstate->ri_IndexRelationInfo;
103  heapRelation = indstate->ri_RelationDesc;
104 
105  /* Need a slot to hold the tuple being examined */
106  slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation),
107  &TTSOpsHeapTuple);
108  ExecStoreHeapTuple(heapTuple, slot, false);
109 
110  /*
111  * for each index, form and insert the index tuple
112  */
113  for (i = 0; i < numIndexes; i++)
114  {
115  IndexInfo *indexInfo;
116  Relation index;
117 
118  indexInfo = indexInfoArray[i];
119  index = relationDescs[i];
120 
121  /* If the index is marked as read-only, ignore it */
122  if (!indexInfo->ii_ReadyForInserts)
123  continue;
124 
125  /*
126  * Expressional and partial indexes on system catalogs are not
127  * supported, nor exclusion constraints, nor deferred uniqueness
128  */
129  Assert(indexInfo->ii_Expressions == NIL);
130  Assert(indexInfo->ii_Predicate == NIL);
131  Assert(indexInfo->ii_ExclusionOps == NULL);
132  Assert(index->rd_index->indimmediate);
133  Assert(indexInfo->ii_NumIndexKeyAttrs != 0);
134 
135  /* see earlier check above */
136 #ifdef USE_ASSERT_CHECKING
137  if (HeapTupleIsHeapOnly(heapTuple))
138  {
140  continue;
141  }
142 #endif /* USE_ASSERT_CHECKING */
143 
144  /*
145  * FormIndexDatum fills in its values and isnull parameters with the
146  * appropriate values for the column(s) of the index.
147  */
148  FormIndexDatum(indexInfo,
149  slot,
150  NULL, /* no expression eval to do */
151  values,
152  isnull);
153 
154  /*
155  * The index AM does the rest.
156  */
157  index_insert(index, /* index relation */
158  values, /* array of index Datums */
159  isnull, /* is-null flags */
160  &(heapTuple->t_self), /* tid of heap tuple */
161  heapRelation,
162  index->rd_index->indisunique ?
164  indexInfo);
165  }
166 
168 }
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:2462
int ri_NumIndices
Definition: execnodes.h:414
#define NIL
Definition: pg_list.h:65
Relation ri_RelationDesc
Definition: execnodes.h:411
List * ii_Predicate
Definition: execnodes.h:162
#define RelationGetDescr(relation)
Definition: rel.h:442
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1203
Definition: type.h:89
Form_pg_index rd_index
Definition: rel.h:143
int ii_NumIndexKeyAttrs
Definition: execnodes.h:158
ItemPointerData t_self
Definition: htup.h:65
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1219
bool ii_ReadyForInserts
Definition: execnodes.h:171
uintptr_t Datum
Definition: postgres.h:367
List * ii_Expressions
Definition: execnodes.h:160
#define HeapTupleIsHeapOnly(tuple)
Definition: htup_details.h:685
#define Assert(condition)
Definition: c.h:732
#define INDEX_MAX_KEYS
static Datum values[MAXATTR]
Definition: bootstrap.c:167
Oid * ii_ExclusionOps
Definition: execnodes.h:164
IndexInfo ** ri_IndexRelationInfo
Definition: execnodes.h:420
int i
const TupleTableSlotOps TTSOpsHeapTuple
Definition: execTuples.c:85
bool ReindexIsProcessingIndex(Oid indexOid)
Definition: index.c:3691
#define RelationGetRelid(relation)
Definition: rel.h:416
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:417
TupleTableSlot * ExecStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
Definition: execTuples.c:1317
bool index_insert(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, IndexInfo *indexInfo)
Definition: indexam.c:170

◆ CatalogOpenIndexes()

CatalogIndexState CatalogOpenIndexes ( Relation  heapRel)

Definition at line 42 of file indexing.c.

References ExecOpenIndices(), makeNode, ResultRelInfo::ri_RangeTableIndex, ResultRelInfo::ri_RelationDesc, and ResultRelInfo::ri_TrigDesc.

Referenced by AddNewAttributeTuples(), AppendAttributeTuples(), CatalogTupleInsert(), CatalogTupleUpdate(), copyTemplateDependencies(), inv_truncate(), inv_write(), recordMultipleDependencies(), and swap_relation_files().

43 {
44  ResultRelInfo *resultRelInfo;
45 
46  resultRelInfo = makeNode(ResultRelInfo);
47  resultRelInfo->ri_RangeTableIndex = 0; /* dummy */
48  resultRelInfo->ri_RelationDesc = heapRel;
49  resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
50 
51  ExecOpenIndices(resultRelInfo, false);
52 
53  return resultRelInfo;
54 }
Relation ri_RelationDesc
Definition: execnodes.h:411
Index ri_RangeTableIndex
Definition: execnodes.h:408
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
Definition: execIndexing.c:151
TriggerDesc * ri_TrigDesc
Definition: execnodes.h:423
#define makeNode(_type_)
Definition: nodes.h:573

◆ CatalogTupleDelete()

void CatalogTupleDelete ( Relation  heapRel,
ItemPointer  tid 
)

Definition at line 269 of file indexing.c.

References simple_heap_delete().

Referenced by AlterSetting(), ATExecAlterColumnType(), changeDependenciesOn(), changeDependencyFor(), CreateComments(), CreateSharedComments(), DeleteAttributeTuples(), DeleteComments(), deleteDependencyRecordsFor(), deleteDependencyRecordsForClass(), DeleteInheritsTuple(), DeleteInitPrivs(), deleteOneObject(), DeleteRelationTuple(), DeleteSecurityLabel(), DeleteSequenceTuple(), DeleteSharedComments(), DeleteSharedSecurityLabel(), DeleteSystemAttributeTuples(), DelRoleMems(), drop_parent_dependency(), DropCastById(), DropConfigurationMapping(), dropDatabaseDependencies(), dropdb(), DropProceduralLanguageById(), DropRole(), DropSetting(), DropSubscription(), DropTableSpace(), DropTransformById(), EnumValuesDelete(), heap_drop_with_catalog(), index_drop(), IndexSetParentIndex(), inv_truncate(), LargeObjectDrop(), MakeConfigurationMapping(), RangeDelete(), recordExtensionInitPrivWorker(), RelationRemoveInheritance(), RemoveAccessMethodById(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefaultById(), RemoveAttributeById(), RemoveCollationById(), RemoveConstraintById(), RemoveConversionById(), RemoveDefaultACLById(), RemoveEventTriggerById(), RemoveExtensionById(), RemoveForeignDataWrapperById(), RemoveForeignServerById(), RemoveFunctionById(), RemoveOpClassById(), RemoveOperatorById(), RemoveOpFamilyById(), RemovePartitionKeyByRelId(), RemovePolicyById(), RemovePublicationById(), RemovePublicationRelById(), RemoveRewriteRuleById(), RemoveSchemaById(), RemoveStatistics(), RemoveStatisticsById(), RemoveSubscriptionRel(), RemoveTriggerById(), RemoveTSConfigurationById(), RemoveTSDictionaryById(), RemoveTSParserById(), RemoveTSTemplateById(), RemoveTypeById(), RemoveUserMappingById(), replorigin_drop(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepChangeDep(), and shdepDropDependency().

270 {
271  simple_heap_delete(heapRel, tid);
272 }
void simple_heap_delete(Relation relation, ItemPointer tid)
Definition: heapam.c:2847

◆ CatalogTupleInsert()

void CatalogTupleInsert ( Relation  heapRel,
HeapTuple  tup 
)

Definition at line 183 of file indexing.c.

References CatalogCloseIndexes(), CatalogIndexInsert(), CatalogOpenIndexes(), and simple_heap_insert().

Referenced by AddEnumLabel(), AddRoleMems(), AddSubscriptionRelState(), AggregateCreate(), AlterSetting(), CollationCreate(), ConversionCreate(), create_proc_lang(), CreateAccessMethod(), CreateCast(), CreateComments(), CreateConstraintEntry(), createdb(), CreateForeignDataWrapper(), CreateForeignServer(), CreateForeignTable(), CreateOpFamily(), CreatePolicy(), CreatePublication(), CreateRole(), CreateSharedComments(), CreateStatistics(), CreateSubscription(), CreateTableSpace(), CreateTransform(), CreateTrigger(), CreateUserMapping(), DefineOpClass(), DefineSequence(), DefineTSConfiguration(), DefineTSDictionary(), DefineTSParser(), DefineTSTemplate(), EnumValuesCreate(), IndexSetParentIndex(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertPgAttributeTuple(), InsertPgClassTuple(), InsertRule(), LargeObjectCreate(), MakeConfigurationMapping(), NamespaceCreate(), OperatorCreate(), OperatorShellMake(), ProcedureCreate(), publication_add_relation(), RangeCreate(), recordExtensionInitPrivWorker(), replorigin_create(), SetDefaultACL(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepAddDependency(), shdepChangeDep(), StoreAttrDefault(), storeOperators(), StorePartitionKey(), storeProcedures(), StoreSingleInheritance(), TypeCreate(), TypeShellMake(), update_attstats(), and UpdateIndexRelation().

184 {
185  CatalogIndexState indstate;
186 
187  indstate = CatalogOpenIndexes(heapRel);
188 
189  simple_heap_insert(heapRel, tup);
190 
191  CatalogIndexInsert(indstate, tup);
192  CatalogCloseIndexes(indstate);
193 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:74
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2384
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Definition: indexing.c:42
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:60

◆ CatalogTupleInsertWithInfo()

void CatalogTupleInsertWithInfo ( Relation  heapRel,
HeapTuple  tup,
CatalogIndexState  indstate 
)

Definition at line 204 of file indexing.c.

References CatalogIndexInsert(), and simple_heap_insert().

Referenced by copyTemplateDependencies(), InsertPgAttributeTuple(), inv_truncate(), inv_write(), and recordMultipleDependencies().

206 {
207  simple_heap_insert(heapRel, tup);
208 
209  CatalogIndexInsert(indstate, tup);
210 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:74
void simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2384

◆ CatalogTupleUpdate()

void CatalogTupleUpdate ( Relation  heapRel,
ItemPointer  otid,
HeapTuple  tup 
)

Definition at line 224 of file indexing.c.

References CatalogCloseIndexes(), CatalogIndexInsert(), CatalogOpenIndexes(), and simple_heap_update().

Referenced by AddRoleMems(), AggregateCreate(), AlterCollation(), AlterConstraintNamespaces(), AlterDatabase(), AlterDatabaseOwner(), AlterDomainDefault(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEventTrigger(), AlterEventTriggerOwner_internal(), AlterExtensionNamespace(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner_internal(), AlterForeignServer(), AlterForeignServerOwner_internal(), AlterFunction(), AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), AlterOperator(), AlterPolicy(), AlterPublicationOptions(), AlterPublicationOwner_internal(), AlterRelationNamespaceInternal(), AlterRole(), AlterSchemaOwner_internal(), AlterSequence(), AlterSetting(), AlterStatistics(), AlterSubscription(), AlterSubscriptionOwner_internal(), AlterTableSpaceOptions(), AlterTSDictionary(), AlterTypeNamespaceInternal(), AlterTypeOwnerInternal(), AlterUserMapping(), ApplyExtensionUpdates(), ATExecAddColumn(), ATExecAddIdentity(), ATExecAddOf(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecAlterConstraint(), ATExecChangeOwner(), ATExecDetachPartition(), ATExecDisableRowSecurity(), ATExecDropColumn(), ATExecDropConstraint(), ATExecDropIdentity(), ATExecDropNotNull(), ATExecDropOf(), ATExecEnableRowSecurity(), ATExecForceNoForceRowSecurity(), ATExecGenericOptions(), ATExecSetIdentity(), ATExecSetNotNull(), ATExecSetOptions(), ATExecSetRelOptions(), ATExecSetStatistics(), ATExecSetStorage(), ATExecSetTableSpace(), ATExecSetTableSpaceNoStorage(), ATExecValidateConstraint(), change_owner_fix_column_acls(), changeDependenciesOf(), changeDependenciesOn(), changeDependencyFor(), ConstraintSetParentConstraint(), copy_table_data(), create_proc_lang(), create_toast_table(), CreateComments(), CreateSharedComments(), CreateTransform(), CreateTrigger(), DefineIndex(), DefineQueryRewrite(), DelRoleMems(), EnableDisableRule(), EnableDisableTrigger(), ExecGrant_Attribute(), ExecGrant_Database(), ExecGrant_Fdw(), ExecGrant_ForeignServer(), ExecGrant_Function(), ExecGrant_Language(), ExecGrant_Largeobject(), ExecGrant_Namespace(), ExecGrant_Relation(), ExecGrant_Tablespace(), ExecGrant_Type(), extension_config_remove(), finish_heap_swap(), index_build(), index_concurrently_swap(), index_constraint_create(), InsertRule(), MakeConfigurationMapping(), mark_index_clustered(), MergeAttributesIntoExisting(), MergeConstraintsIntoExisting(), MergeWithExistingConstraint(), movedb(), OperatorCreate(), OperatorUpd(), pg_extension_config_dump(), ProcedureCreate(), recordExtensionInitPrivWorker(), reindex_index(), relation_mark_replica_identity(), RelationClearMissing(), RelationSetNewRelfilenode(), RemoveAttrDefaultById(), RemoveAttributeById(), RemoveConstraintById(), RemoveInheritance(), RemoveRoleFromObjectPolicy(), rename_policy(), renameatt_internal(), RenameConstraintById(), RenameDatabase(), RenameEnumLabel(), RenameRelationInternal(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameTypeInternal(), RenumberEnumType(), SetAttrMissing(), SetDefaultACL(), SetFunctionArgType(), SetFunctionReturnType(), SetMatViewPopulatedState(), SetRelationHasSubclass(), SetRelationNumChecks(), SetRelationRuleStatus(), SetSecurityLabel(), SetSharedSecurityLabel(), shdepChangeDep(), statext_store(), StoreAttrDefault(), StorePartitionBound(), TypeCreate(), update_attstats(), update_default_partition_oid(), update_relispartition(), UpdateStatisticsForTypeChange(), UpdateSubscriptionRelState(), and validatePartitionedIndex().

225 {
226  CatalogIndexState indstate;
227 
228  indstate = CatalogOpenIndexes(heapRel);
229 
230  simple_heap_update(heapRel, otid, tup);
231 
232  CatalogIndexInsert(indstate, tup);
233  CatalogCloseIndexes(indstate);
234 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:74
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Definition: indexing.c:42
void simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
Definition: heapam.c:3885
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:60

◆ CatalogTupleUpdateWithInfo()

void CatalogTupleUpdateWithInfo ( Relation  heapRel,
ItemPointer  otid,
HeapTuple  tup,
CatalogIndexState  indstate 
)

Definition at line 245 of file indexing.c.

References CatalogIndexInsert(), and simple_heap_update().

Referenced by inv_truncate(), inv_write(), and swap_relation_files().

247 {
248  simple_heap_update(heapRel, otid, tup);
249 
250  CatalogIndexInsert(indstate, tup);
251 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:74
void simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
Definition: heapam.c:3885