PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

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:950
void ExecCloseIndices(ResultRelInfo *resultRelInfo)
Definition: execIndexing.c:224
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_Predicate, IndexInfo::ii_ReadyForInserts, index_insert(), INDEX_MAX_KEYS, InvalidBuffer, MakeSingleTupleTableSlot(), NIL, NULL, 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 
123  /*
124  * FormIndexDatum fills in its values and isnull parameters with the
125  * appropriate values for the column(s) of the index.
126  */
127  FormIndexDatum(indexInfo,
128  slot,
129  NULL, /* no expression eval to do */
130  values,
131  isnull);
132 
133  /*
134  * The index AM does the rest.
135  */
136  index_insert(relationDescs[i], /* index relation */
137  values, /* array of index Datums */
138  isnull, /* is-null flags */
139  &(heapTuple->t_self), /* tid of heap tuple */
140  heapRelation,
141  relationDescs[i]->rd_index->indisunique ?
143  indexInfo);
144  }
145 
147 }
void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)
Definition: index.c:1768
int ri_NumIndices
Definition: execnodes.h:357
#define NIL
Definition: pg_list.h:69
TupleTableSlot * ExecStoreTuple(HeapTuple tuple, TupleTableSlot *slot, Buffer buffer, bool shouldFree)
Definition: execTuples.c:320
Relation ri_RelationDesc
Definition: execnodes.h:354
List * ii_Predicate
Definition: execnodes.h:138
#define RelationGetDescr(relation)
Definition: rel.h:428
#define InvalidBuffer
Definition: buf.h:25
Form_pg_index rd_index
Definition: rel.h:159
ItemPointerData t_self
Definition: htup.h:65
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:216
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc)
Definition: execTuples.c:199
bool ii_ReadyForInserts
Definition: execnodes.h:147
uintptr_t Datum
Definition: postgres.h:372
#define NULL
Definition: c.h:229
List * ii_Expressions
Definition: execnodes.h:136
#define HeapTupleIsHeapOnly(tuple)
Definition: htup_details.h:686
#define Assert(condition)
Definition: c.h:676
#define INDEX_MAX_KEYS
static Datum values[MAXATTR]
Definition: bootstrap.c:163
Oid * ii_ExclusionOps
Definition: execnodes.h:140
IndexInfo ** ri_IndexRelationInfo
Definition: execnodes.h:363
int i
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:360
bool index_insert(Relation indexRelation, Datum *values, bool *isnull, ItemPointer heap_t_ctid, Relation heapRelation, IndexUniqueCheck checkUnique, IndexInfo *indexInfo)
Definition: indexam.c:194
CatalogIndexState CatalogOpenIndexes ( Relation  heapRel)

Definition at line 40 of file indexing.c.

References ExecOpenIndices(), makeNode, NULL, 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:354
Index ri_RangeTableIndex
Definition: execnodes.h:351
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
Definition: execIndexing.c:149
TriggerDesc * ri_TrigDesc
Definition: execnodes.h:366
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
void CatalogTupleDelete ( Relation  heapRel,
ItemPointer  tid 
)

Definition at line 255 of file indexing.c.

References simple_heap_delete().

Referenced by AlterSetting(), ATExecAlterColumnType(), changeDependencyFor(), CreateComments(), CreateSharedComments(), DeleteAttributeTuples(), DeleteComments(), deleteDependencyRecordsFor(), deleteDependencyRecordsForClass(), 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(), inv_truncate(), LargeObjectDrop(), MakeConfigurationMapping(), RangeDelete(), recordExtensionInitPrivWorker(), RelationRemoveInheritance(), RemoveAccessMethodById(), RemoveAmOpEntryById(), RemoveAmProcEntryById(), RemoveAttrDefaultById(), RemoveAttributeById(), RemoveCollationById(), RemoveConstraintById(), RemoveConversionById(), RemoveDefaultACLById(), RemoveEventTriggerById(), RemoveExtensionById(), RemoveForeignDataWrapperById(), RemoveForeignServerById(), RemoveFunctionById(), RemoveInheritance(), 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().

256 {
257  simple_heap_delete(heapRel, tid);
258 }
void simple_heap_delete(Relation relation, ItemPointer tid)
Definition: heapam.c:3414
Oid CatalogTupleInsert ( Relation  heapRel,
HeapTuple  tup 
)

Definition at line 162 of file indexing.c.

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

Referenced by AddEnumLabel(), AddRoleMems(), 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(), insert_event_trigger_tuple(), InsertExtensionTuple(), InsertPgAttributeTuple(), InsertPgClassTuple(), InsertRule(), LargeObjectCreate(), MakeConfigurationMapping(), NamespaceCreate(), OperatorCreate(), OperatorShellMake(), ProcedureCreate(), publication_add_relation(), RangeCreate(), recordExtensionInitPrivWorker(), replorigin_create(), SetDefaultACL(), SetSecurityLabel(), SetSharedSecurityLabel(), SetSubscriptionRelState(), shdepAddDependency(), shdepChangeDep(), StoreAttrDefault(), StoreCatalogInheritance1(), storeOperators(), StorePartitionKey(), storeProcedures(), TypeCreate(), TypeShellMake(), update_attstats(), and UpdateIndexRelation().

163 {
164  CatalogIndexState indstate;
165  Oid oid;
166 
167  indstate = CatalogOpenIndexes(heapRel);
168 
169  oid = simple_heap_insert(heapRel, tup);
170 
171  CatalogIndexInsert(indstate, tup);
172  CatalogCloseIndexes(indstate);
173 
174  return oid;
175 }
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:2955
CatalogIndexState CatalogOpenIndexes(Relation heapRel)
Definition: indexing.c:40
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:58
Oid CatalogTupleInsertWithInfo ( Relation  heapRel,
HeapTuple  tup,
CatalogIndexState  indstate 
)

Definition at line 186 of file indexing.c.

References CatalogIndexInsert(), and simple_heap_insert().

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

188 {
189  Oid oid;
190 
191  oid = simple_heap_insert(heapRel, tup);
192 
193  CatalogIndexInsert(indstate, tup);
194 
195  return oid;
196 }
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:2955
void CatalogTupleUpdate ( Relation  heapRel,
ItemPointer  otid,
HeapTuple  tup 
)

Definition at line 210 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(), create_proc_lang(), create_toast_table(), CreateComments(), CreateSharedComments(), CreateTransform(), CreateTrigger(), 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(), RelationSetNewRelfilenode(), RemoveAttrDefaultById(), RemoveAttributeById(), RemoveConstraintById(), RemoveInheritance(), RemoveRoleFromObjectPolicy(), rename_policy(), renameatt_internal(), RenameConstraintById(), RenameDatabase(), RenameEnumLabel(), RenameRelationInternal(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameTypeInternal(), RenumberEnumType(), SetDefaultACL(), SetFunctionArgType(), SetFunctionReturnType(), SetMatViewPopulatedState(), SetRelationHasSubclass(), SetRelationNumChecks(), SetRelationRuleStatus(), SetSecurityLabel(), SetSharedSecurityLabel(), SetSubscriptionRelState(), shdepChangeDep(), statext_store(), StoreAttrDefault(), StorePartitionBound(), TypeCreate(), and update_attstats().

211 {
212  CatalogIndexState indstate;
213 
214  indstate = CatalogOpenIndexes(heapRel);
215 
216  simple_heap_update(heapRel, otid, tup);
217 
218  CatalogIndexInsert(indstate, tup);
219  CatalogCloseIndexes(indstate);
220 }
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:4468
void CatalogCloseIndexes(CatalogIndexState indstate)
Definition: indexing.c:58
void CatalogTupleUpdateWithInfo ( Relation  heapRel,
ItemPointer  otid,
HeapTuple  tup,
CatalogIndexState  indstate 
)

Definition at line 231 of file indexing.c.

References CatalogIndexInsert(), and simple_heap_update().

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

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