PostgreSQL Source Code  git master
indexing.c File Reference
#include "postgres.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)
 
Oid CatalogTupleInsert (Relation heapRel, HeapTuple tup)
 
Oid 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 58 of file indexing.c.

References ExecCloseIndices(), and pfree().

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

59 {
60  ExecCloseIndices(indstate);
61  pfree(indstate);
62 }
void pfree(void *pointer)
Definition: mcxt.c:1031
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
Definition: execIndexing.c:224

◆ CatalogIndexInsert()

static void CatalogIndexInsert ( CatalogIndexState  indstate,
HeapTuple  heapTuple 
)
static

Definition at line 72 of file indexing.c.

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

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

73 {
74  int i;
75  int numIndexes;
76  RelationPtr relationDescs;
77  Relation heapRelation;
78  TupleTableSlot *slot;
79  IndexInfo **indexInfoArray;
81  bool isnull[INDEX_MAX_KEYS];
82 
83  /* HOT update does not require index inserts */
84  if (HeapTupleIsHeapOnly(heapTuple))
85  return;
86 
87  /*
88  * Get information from the state structure. Fall out if nothing to do.
89  */
90  numIndexes = indstate->ri_NumIndices;
91  if (numIndexes == 0)
92  return;
93  relationDescs = indstate->ri_IndexRelationDescs;
94  indexInfoArray = indstate->ri_IndexRelationInfo;
95  heapRelation = indstate->ri_RelationDesc;
96 
97  /* Need a slot to hold the tuple being examined */
98  slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
99  ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);
100 
101  /*
102  * for each index, form and insert the index tuple
103  */
104  for (i = 0; i < numIndexes; i++)
105  {
106  IndexInfo *indexInfo;
107 
108  indexInfo = indexInfoArray[i];
109 
110  /* If the index is marked as read-only, ignore it */
111  if (!indexInfo->ii_ReadyForInserts)
112  continue;
113 
114  /*
115  * Expressional and partial indexes on system catalogs are not
116  * supported, nor exclusion constraints, nor deferred uniqueness
117  */
118  Assert(indexInfo->ii_Expressions == NIL);
119  Assert(indexInfo->ii_Predicate == NIL);
120  Assert(indexInfo->ii_ExclusionOps == NULL);
121  Assert(relationDescs[i]->rd_index->indimmediate);
122  Assert(indexInfo->ii_NumIndexKeyAttrs != 0);
123 
124  /*
125  * FormIndexDatum fills in its values and isnull parameters with the
126  * appropriate values for the column(s) of the index.
127  */
128  FormIndexDatum(indexInfo,
129  slot,
130  NULL, /* no expression eval to do */
131  values,
132  isnull);
133 
134  /*
135  * The index AM does the rest.
136  */
137  index_insert(relationDescs[i], /* index relation */
138  values, /* array of index Datums */
139  isnull, /* is-null flags */
140  &(heapTuple->t_self), /* tid of heap tuple */
141  heapRelation,
142  relationDescs[i]->rd_index->indisunique ?
144  indexInfo);
145  }
146 
148 }
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:2000
int ri_NumIndices
Definition: execnodes.h:400
#define NIL
Definition: pg_list.h:69
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Definition: execTuples.c:356
Relation ri_RelationDesc
Definition: execnodes.h:397
List * ii_Predicate
Definition: execnodes.h:156
#define RelationGetDescr(relation)
Definition: rel.h:433
#define InvalidBuffer
Definition: buf.h:25
Form_pg_index rd_index
Definition: rel.h:131
int ii_NumIndexKeyAttrs
Definition: execnodes.h:152
ItemPointerData t_self
Definition: htup.h:65
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:247
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc)
Definition: execTuples.c:232
bool ii_ReadyForInserts
Definition: execnodes.h:165
uintptr_t Datum
Definition: postgres.h:367
List * ii_Expressions
Definition: execnodes.h:154
#define HeapTupleIsHeapOnly(tuple)
Definition: htup_details.h:698
#define Assert(condition)
Definition: c.h:699
#define INDEX_MAX_KEYS
static Datum values[MAXATTR]
Definition: bootstrap.c:164
Oid * ii_ExclusionOps
Definition: execnodes.h:158
IndexInfo ** ri_IndexRelationInfo
Definition: execnodes.h:406
int i
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:403
bool index_insert(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, IndexInfo *indexInfo)
Definition: indexam.c:194

◆ CatalogOpenIndexes()

CatalogIndexState CatalogOpenIndexes ( Relation  heapRel)

Definition at line 40 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().

41 {
42  ResultRelInfo *resultRelInfo;
43 
44  resultRelInfo = makeNode(ResultRelInfo);
45  resultRelInfo->ri_RangeTableIndex = 1; /* dummy */
46  resultRelInfo->ri_RelationDesc = heapRel;
47  resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
48 
49  ExecOpenIndices(resultRelInfo, false);
50 
51  return resultRelInfo;
52 }
Relation ri_RelationDesc
Definition: execnodes.h:397
Index ri_RangeTableIndex
Definition: execnodes.h:394
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
Definition: execIndexing.c:149
TriggerDesc * ri_TrigDesc
Definition: execnodes.h:409
#define makeNode(_type_)
Definition: nodes.h:564

◆ CatalogTupleDelete()

void CatalogTupleDelete ( Relation  heapRel,
ItemPointer  tid 
)

Definition at line 256 of file indexing.c.

References simple_heap_delete().

Referenced by AlterSetting(), ATExecAlterColumnType(), 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().

257 {
258  simple_heap_delete(heapRel, tid);
259 }
void simple_heap_delete(Relation relation, ItemPointer tid)
Definition: heapam.c:3455

◆ CatalogTupleInsert()

Oid CatalogTupleInsert ( Relation  heapRel,
HeapTuple  tup 
)

Definition at line 163 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().

164 {
165  CatalogIndexState indstate;
166  Oid oid;
167 
168  indstate = CatalogOpenIndexes(heapRel);
169 
170  oid = simple_heap_insert(heapRel, tup);
171 
172  CatalogIndexInsert(indstate, tup);
173  CatalogCloseIndexes(indstate);
174 
175  return oid;
176 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:72
unsigned int Oid
Definition: postgres_ext.h:31
Oid simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2986
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Definition: indexing.c:40
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:58

◆ CatalogTupleInsertWithInfo()

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

Definition at line 187 of file indexing.c.

References CatalogIndexInsert(), and simple_heap_insert().

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

189 {
190  Oid oid;
191 
192  oid = simple_heap_insert(heapRel, tup);
193 
194  CatalogIndexInsert(indstate, tup);
195 
196  return oid;
197 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:72
unsigned int Oid
Definition: postgres_ext.h:31
Oid simple_heap_insert(Relation relation, HeapTuple tup)
Definition: heapam.c:2986

◆ CatalogTupleUpdate()

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

Definition at line 211 of file indexing.c.

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

Referenced by AddRoleMems(), 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(), 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(), ATExecValidateConstraint(), change_owner_fix_column_acls(), changeDependencyFor(), ConstraintSetParentConstraint(), copy_heap_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_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(), UpdateSubscriptionRelState(), and validatePartitionedIndex().

212 {
213  CatalogIndexState indstate;
214 
215  indstate = CatalogOpenIndexes(heapRel);
216 
217  simple_heap_update(heapRel, otid, tup);
218 
219  CatalogIndexInsert(indstate, tup);
220  CatalogCloseIndexes(indstate);
221 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:72
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Definition: indexing.c:40
void simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
Definition: heapam.c:4599
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:58

◆ CatalogTupleUpdateWithInfo()

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

Definition at line 232 of file indexing.c.

References CatalogIndexInsert(), and simple_heap_update().

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

234 {
235  simple_heap_update(heapRel, otid, tup);
236 
237  CatalogIndexInsert(indstate, tup);
238 }
static void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
Definition: indexing.c:72
void simple_heap_update(Relation relation, ItemPointer otid, HeapTuple tup)
Definition: heapam.c:4599