Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "postgres.h"
00017
00018 #include "access/htup_details.h"
00019 #include "catalog/index.h"
00020 #include "catalog/indexing.h"
00021 #include "executor/executor.h"
00022 #include "utils/rel.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 CatalogIndexState
00040 CatalogOpenIndexes(Relation heapRel)
00041 {
00042 ResultRelInfo *resultRelInfo;
00043
00044 resultRelInfo = makeNode(ResultRelInfo);
00045 resultRelInfo->ri_RangeTableIndex = 1;
00046 resultRelInfo->ri_RelationDesc = heapRel;
00047 resultRelInfo->ri_TrigDesc = NULL;
00048
00049 ExecOpenIndices(resultRelInfo);
00050
00051 return resultRelInfo;
00052 }
00053
00054
00055
00056
00057 void
00058 CatalogCloseIndexes(CatalogIndexState indstate)
00059 {
00060 ExecCloseIndices(indstate);
00061 pfree(indstate);
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071 void
00072 CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
00073 {
00074 int i;
00075 int numIndexes;
00076 RelationPtr relationDescs;
00077 Relation heapRelation;
00078 TupleTableSlot *slot;
00079 IndexInfo **indexInfoArray;
00080 Datum values[INDEX_MAX_KEYS];
00081 bool isnull[INDEX_MAX_KEYS];
00082
00083
00084 if (HeapTupleIsHeapOnly(heapTuple))
00085 return;
00086
00087
00088
00089
00090 numIndexes = indstate->ri_NumIndices;
00091 if (numIndexes == 0)
00092 return;
00093 relationDescs = indstate->ri_IndexRelationDescs;
00094 indexInfoArray = indstate->ri_IndexRelationInfo;
00095 heapRelation = indstate->ri_RelationDesc;
00096
00097
00098 slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
00099 ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);
00100
00101
00102
00103
00104 for (i = 0; i < numIndexes; i++)
00105 {
00106 IndexInfo *indexInfo;
00107
00108 indexInfo = indexInfoArray[i];
00109
00110
00111 if (!indexInfo->ii_ReadyForInserts)
00112 continue;
00113
00114
00115
00116
00117
00118 Assert(indexInfo->ii_Expressions == NIL);
00119 Assert(indexInfo->ii_Predicate == NIL);
00120 Assert(indexInfo->ii_ExclusionOps == NULL);
00121 Assert(relationDescs[i]->rd_index->indimmediate);
00122
00123
00124
00125
00126
00127 FormIndexDatum(indexInfo,
00128 slot,
00129 NULL,
00130 values,
00131 isnull);
00132
00133
00134
00135
00136 index_insert(relationDescs[i],
00137 values,
00138 isnull,
00139 &(heapTuple->t_self),
00140 heapRelation,
00141 relationDescs[i]->rd_index->indisunique ?
00142 UNIQUE_CHECK_YES : UNIQUE_CHECK_NO);
00143 }
00144
00145 ExecDropSingleTupleTableSlot(slot);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 void
00157 CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple)
00158 {
00159 CatalogIndexState indstate;
00160
00161 indstate = CatalogOpenIndexes(heapRel);
00162 CatalogIndexInsert(indstate, heapTuple);
00163 CatalogCloseIndexes(indstate);
00164 }