1
/*-------------------------------------------------------------------------
4
* This file contains routines to support indexes defined on system
7
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
12
* $PostgreSQL: pgsql/src/backend/catalog/indexing.c,v 1.107 2004-12-31 21:59:38 pgsql Exp $
14
*-------------------------------------------------------------------------
18
#include "access/genam.h"
19
#include "catalog/index.h"
20
#include "catalog/indexing.h"
21
#include "executor/executor.h"
25
* CatalogOpenIndexes - open the indexes on a system catalog.
27
* When inserting or updating tuples in a system catalog, call this
28
* to prepare to update the indexes for the catalog.
30
* In the current implementation, we share code for opening/closing the
31
* indexes with execUtils.c. But we do not use ExecInsertIndexTuples,
32
* because we don't want to create an EState. This implies that we
33
* do not support partial or expressional indexes on system catalogs.
34
* This could be fixed with localized changes here if we wanted to pay
35
* the extra overhead of building an EState.
38
CatalogOpenIndexes(Relation heapRel)
40
ResultRelInfo *resultRelInfo;
42
resultRelInfo = makeNode(ResultRelInfo);
43
resultRelInfo->ri_RangeTableIndex = 1; /* dummy */
44
resultRelInfo->ri_RelationDesc = heapRel;
45
resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
47
ExecOpenIndices(resultRelInfo);
53
* CatalogCloseIndexes - clean up resources allocated by CatalogOpenIndexes
56
CatalogCloseIndexes(CatalogIndexState indstate)
58
ExecCloseIndices(indstate);
63
* CatalogIndexInsert - insert index entries for one catalog tuple
65
* This should be called for each inserted or updated catalog tuple.
67
* This is effectively a cut-down version of ExecInsertIndexTuples.
70
CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
74
RelationPtr relationDescs;
75
Relation heapRelation;
76
TupleDesc heapDescriptor;
77
IndexInfo **indexInfoArray;
78
Datum datum[INDEX_MAX_KEYS];
79
char nullv[INDEX_MAX_KEYS];
82
* Get information from the state structure.
84
numIndexes = indstate->ri_NumIndices;
85
relationDescs = indstate->ri_IndexRelationDescs;
86
indexInfoArray = indstate->ri_IndexRelationInfo;
87
heapRelation = indstate->ri_RelationDesc;
88
heapDescriptor = RelationGetDescr(heapRelation);
91
* for each index, form and insert the index tuple
93
for (i = 0; i < numIndexes; i++)
96
InsertIndexResult result;
98
indexInfo = indexInfoArray[i];
101
* Expressional and partial indexes on system catalogs are not
104
Assert(indexInfo->ii_Expressions == NIL);
105
Assert(indexInfo->ii_Predicate == NIL);
108
* FormIndexDatum fills in its datum and null parameters with
109
* attribute information taken from the given heap tuple.
111
FormIndexDatum(indexInfo,
114
NULL, /* no expression eval to do */
119
* The index AM does the rest.
121
result = index_insert(relationDescs[i], /* index relation */
122
datum, /* array of heaptuple Datums */
123
nullv, /* info on nulls */
124
&(heapTuple->t_self), /* tid of heap tuple */
126
relationDescs[i]->rd_index->indisunique);
134
* CatalogUpdateIndexes - do all the indexing work for a new catalog tuple
136
* This is a convenience routine for the common case where we only need
137
* to insert or update a single tuple in a system catalog. Avoid using it for
138
* multiple tuples, since opening the indexes and building the index info
139
* structures is moderately expensive.
142
CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple)
144
CatalogIndexState indstate;
146
indstate = CatalogOpenIndexes(heapRel);
147
CatalogIndexInsert(indstate, heapTuple);
148
CatalogCloseIndexes(indstate);