*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.72 2002/07/29 22:14:10 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.73 2002/08/05 03:29:16 tgl Exp $
*
* NOTES
* See acl.h.
simple_heap_update(relation, &newtuple->t_self, newtuple);
- {
- /* keep the catalog indexes up to date */
- Relation idescs[Num_pg_class_indices];
-
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, relation, newtuple);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
- }
+ /* keep the catalog indexes up to date */
+ CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
simple_heap_update(relation, &newtuple->t_self, newtuple);
- {
- /* keep the catalog indexes up to date */
- Relation idescs[Num_pg_database_indices];
-
- CatalogOpenIndices(Num_pg_database_indices, Name_pg_database_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_database_indices, relation, newtuple);
- CatalogCloseIndices(Num_pg_database_indices, idescs);
- }
+ /* keep the catalog indexes up to date */
+ CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
simple_heap_update(relation, &newtuple->t_self, newtuple);
- {
- /* keep the catalog indexes up to date */
- Relation idescs[Num_pg_proc_indices];
-
- CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_proc_indices, relation, newtuple);
- CatalogCloseIndices(Num_pg_proc_indices, idescs);
- }
+ /* keep the catalog indexes up to date */
+ CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
simple_heap_update(relation, &newtuple->t_self, newtuple);
- {
- /* keep the catalog indexes up to date */
- Relation idescs[Num_pg_language_indices];
-
- CatalogOpenIndices(Num_pg_language_indices, Name_pg_language_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_language_indices, relation, newtuple);
- CatalogCloseIndices(Num_pg_language_indices, idescs);
- }
+ /* keep the catalog indexes up to date */
+ CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
simple_heap_update(relation, &newtuple->t_self, newtuple);
- {
- /* keep the catalog indexes up to date */
- Relation idescs[Num_pg_namespace_indices];
-
- CatalogOpenIndices(Num_pg_namespace_indices, Name_pg_namespace_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_namespace_indices, relation, newtuple);
- CatalogCloseIndices(Num_pg_namespace_indices, idescs);
- }
+ /* keep the catalog indexes up to date */
+ CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.217 2002/08/05 02:30:50 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.218 2002/08/05 03:29:16 tgl Exp $
*
*
* INTERFACE ROUTINES
int i;
HeapTuple tup;
Relation rel;
- bool hasindex;
- Relation idescs[Num_pg_attr_indices];
+ CatalogIndexState indstate;
int natts = tupdesc->natts;
ObjectAddress myself,
referenced;
/*
- * open pg_attribute
+ * open pg_attribute and its indexes.
*/
rel = heap_openr(AttributeRelationName, RowExclusiveLock);
- /*
- * Check if we have any indices defined on pg_attribute.
- */
- hasindex = RelationGetForm(rel)->relhasindex;
- if (hasindex)
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
+ indstate = CatalogOpenIndexes(rel);
/*
* First we add the user attributes. This is also a convenient place
simple_heap_insert(rel, tup);
- if (hasindex)
- CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
+ CatalogIndexInsert(indstate, tup);
heap_freetuple(tup);
simple_heap_insert(rel, tup);
- if (hasindex)
- CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
+ CatalogIndexInsert(indstate, tup);
heap_freetuple(tup);
}
/*
* clean up
*/
- if (hasindex)
- CatalogCloseIndices(Num_pg_attr_indices, idescs);
+ CatalogCloseIndexes(indstate);
heap_close(rel, RowExclusiveLock);
}
{
Form_pg_class new_rel_reltup;
HeapTuple tup;
- Relation idescs[Num_pg_class_indices];
/*
* first we update some of the information in our uncataloged
HeapTupleSetOid(tup, new_rel_oid);
/*
- * finally insert the new tuple and free it.
+ * finally insert the new tuple, update the indexes, and clean up.
*/
simple_heap_insert(pg_class_desc, tup);
- if (!IsIgnoringSystemIndexes())
- {
- /*
- * First, open the catalog indices and insert index tuples for the
- * new relation.
- */
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class_desc, tup);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_class_desc, tup);
heap_freetuple(tup);
}
simple_heap_update(attr_rel, &tuple->t_self, tuple);
- /* keep the system catalog indices current */
- if (RelationGetForm(attr_rel)->relhasindex)
- {
- Relation idescs[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
- CatalogCloseIndices(Num_pg_attr_indices, idescs);
- }
+ /* keep the system catalog indexes current */
+ CatalogUpdateIndexes(attr_rel, tuple);
/*
* Because updating the pg_attribute row will trigger a relcache flush
simple_heap_update(attr_rel, &tuple->t_self, tuple);
- /* keep the system catalog indices current */
- if (RelationGetForm(attr_rel)->relhasindex)
- {
- Relation idescs[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
- CatalogCloseIndices(Num_pg_attr_indices, idescs);
- }
+ /* keep the system catalog indexes current */
+ CatalogUpdateIndexes(attr_rel, tuple);
/*
* Our update of the pg_attribute row will force a relcache rebuild,
Node *expr;
char *adsrc;
Relation adrel;
- Relation idescs[Num_pg_attrdef_indices];
HeapTuple tuple;
Datum values[4];
static char nulls[4] = {' ', ' ', ' ', ' '};
Relation attrrel;
- Relation attridescs[Num_pg_attr_indices];
HeapTuple atttup;
Form_pg_attribute attStruct;
Oid attrdefOid;
tuple = heap_formtuple(adrel->rd_att, values, nulls);
attrdefOid = simple_heap_insert(adrel, tuple);
- CatalogOpenIndices(Num_pg_attrdef_indices, Name_pg_attrdef_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_attrdef_indices, adrel, tuple);
- CatalogCloseIndices(Num_pg_attrdef_indices, idescs);
+ CatalogUpdateIndexes(adrel, tuple);
defobject.classId = RelationGetRelid(adrel);
defobject.objectId = attrdefOid;
{
attStruct->atthasdef = true;
simple_heap_update(attrrel, &atttup->t_self, atttup);
- /* keep catalog indices current */
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices,
- attridescs);
- CatalogIndexInsert(attridescs, Num_pg_attr_indices, attrrel, atttup);
- CatalogCloseIndices(Num_pg_attr_indices, attridescs);
+ /* keep catalog indexes current */
+ CatalogUpdateIndexes(attrrel, atttup);
}
heap_close(attrrel, RowExclusiveLock);
heap_freetuple(atttup);
Relation relrel;
HeapTuple reltup;
Form_pg_class relStruct;
- Relation relidescs[Num_pg_class_indices];
relrel = heap_openr(RelationRelationName, RowExclusiveLock);
reltup = SearchSysCacheCopy(RELOID,
simple_heap_update(relrel, &reltup->t_self, reltup);
- /* keep catalog indices current */
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
- relidescs);
- CatalogIndexInsert(relidescs, Num_pg_class_indices, relrel, reltup);
- CatalogCloseIndices(Num_pg_class_indices, relidescs);
+ /* keep catalog indexes current */
+ CatalogUpdateIndexes(relrel, reltup);
}
else
{
/*
* RelationTruncateIndexes - truncate all
- * indices associated with the heap relation to zero tuples.
+ * indexes associated with the heap relation to zero tuples.
*
- * The routine will truncate and then reconstruct the indices on
+ * The routine will truncate and then reconstruct the indexes on
* the relation specified by the heapId parameter.
*/
static void
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.187 2002/07/29 22:14:10 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.188 2002/08/05 03:29:16 tgl Exp $
*
*
* INTERFACE ROUTINES
{
Relation pg_class;
HeapTuple tuple;
- Relation idescs[Num_pg_class_indices];
pg_class = heap_openr(RelationRelationName, RowExclusiveLock);
HeapTupleSetOid(tuple, RelationGetRelid(indexRelation));
simple_heap_insert(pg_class, tuple);
- /*
- * During normal processing, we need to make sure that the system
- * catalog indices are correct. Bootstrap (initdb) time doesn't
- * require this, because we make sure that the indices are correct
- * just before exiting.
- */
- if (!IsIgnoringSystemIndexes())
- {
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, tuple);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
- }
+ /* update the system catalog indexes */
+ CatalogUpdateIndexes(pg_class, tuple);
heap_freetuple(tuple);
heap_close(pg_class, RowExclusiveLock);
AppendAttributeTuples(Relation indexRelation, int numatts)
{
Relation pg_attribute;
- bool hasind;
- Relation idescs[Num_pg_attr_indices];
+ CatalogIndexState indstate;
TupleDesc indexTupDesc;
HeapTuple new_tuple;
int i;
/*
- * open the attribute relation
+ * open the attribute relation and its indexes
*/
pg_attribute = heap_openr(AttributeRelationName, RowExclusiveLock);
- hasind = false;
- if (!IsIgnoringSystemIndexes() && pg_attribute->rd_rel->relhasindex)
- {
- hasind = true;
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
- }
+ indstate = CatalogOpenIndexes(pg_attribute);
/*
* insert data from new index's tupdesc into pg_attribute
simple_heap_insert(pg_attribute, new_tuple);
- if (hasind)
- CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, new_tuple);
+ CatalogIndexInsert(indstate, new_tuple);
heap_freetuple(new_tuple);
}
- if (hasind)
- CatalogCloseIndices(Num_pg_attr_indices, idescs);
+ CatalogCloseIndexes(indstate);
heap_close(pg_attribute, RowExclusiveLock);
}
Relation pg_index;
HeapTuple tuple;
int i;
- Relation idescs[Num_pg_index_indices];
/*
* allocate a Form_pg_index big enough to hold the index-predicate (if
(void *) indexForm);
/*
- * insert the tuple into the pg_index
+ * insert the tuple into the pg_index catalog
*/
simple_heap_insert(pg_index, tuple);
- /*
- * add index tuples for it
- */
- if (!IsIgnoringSystemIndexes())
- {
- CatalogOpenIndices(Num_pg_index_indices, Name_pg_index_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_index_indices, pg_index, tuple);
- CatalogCloseIndices(Num_pg_index_indices, idescs);
- }
+ /* update the indexes on pg_index */
+ CatalogUpdateIndexes(pg_index, tuple);
/*
* close the relation and free the tuple
/*
* If this is bootstrap (initdb) time, then we don't actually fill in
- * the index yet. We'll be creating more indices and classes later,
+ * the index yet. We'll be creating more indexes and classes later,
* so we delay filling them in until just before we're done with
* bootstrapping. Otherwise, we call the routine that constructs the
* index.
{
simple_heap_update(pg_class, &tuple->t_self, tuple);
- /* Keep the catalog indices up to date */
- if (!IsIgnoringSystemIndexes())
- {
- Relation idescs[Num_pg_class_indices];
-
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, tuple);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
- }
+ /* Keep the catalog indexes up to date */
+ CatalogUpdateIndexes(pg_class, tuple);
}
else
{
void
setNewRelfilenode(Relation relation)
{
- Relation pg_class,
- idescs[Num_pg_class_indices];
+ Relation pg_class;
Oid newrelfilenode;
bool in_place_update = false;
HeapTupleData lockTupleData;
WriteBuffer(buffer);
BufferSync();
}
- /* Keep the catalog indices up to date */
- if (!in_place_update && pg_class->rd_rel->relhasindex)
- {
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, classTuple);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
- }
+ /* Keep the catalog indexes up to date */
+ if (!in_place_update)
+ CatalogUpdateIndexes(pg_class, classTuple);
+
heap_close(pg_class, NoLock);
if (!in_place_update)
heap_freetuple(classTuple);
BlockNumber relpages;
int i;
Form_pg_class rd_rel;
- Relation idescs[Num_pg_class_indices];
Datum values[Natts_pg_class];
char nulls[Natts_pg_class];
char replace[Natts_pg_class];
values[Anum_pg_class_reltuples - 1] = Float4GetDatum((float4) reltuples);
newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace);
simple_heap_update(pg_class, &tuple->t_self, newtup);
- if (!IsIgnoringSystemIndexes())
- {
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, newtup);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_class, newtup);
heap_freetuple(newtup);
}
/*-------------------------------------------------------------------------
*
* indexing.c
- * This file contains routines to support indices defined on system
+ * This file contains routines to support indexes defined on system
* catalogs.
*
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.99 2002/07/22 20:23:19 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.100 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
-
#include "postgres.h"
#include "access/genam.h"
-#include "access/heapam.h"
-#include "catalog/catalog.h"
-#include "catalog/catname.h"
#include "catalog/index.h"
#include "catalog/indexing.h"
-#include "catalog/pg_index.h"
-#include "miscadmin.h"
-#include "utils/fmgroids.h"
-#include "utils/syscache.h"
-
-/*
- * Names of indices for each system catalog.
- */
-
-char *Name_pg_aggregate_indices[Num_pg_aggregate_indices] =
-{AggregateFnoidIndex};
-char *Name_pg_am_indices[Num_pg_am_indices] =
-{AmNameIndex, AmOidIndex};
-char *Name_pg_amop_indices[Num_pg_amop_indices] =
-{AccessMethodOperatorIndex, AccessMethodStrategyIndex};
-char *Name_pg_amproc_indices[Num_pg_amproc_indices] =
-{AccessMethodProcedureIndex};
-char *Name_pg_attr_indices[Num_pg_attr_indices] =
-{AttributeRelidNameIndex, AttributeRelidNumIndex};
-char *Name_pg_attrdef_indices[Num_pg_attrdef_indices] =
-{AttrDefaultIndex, AttrDefaultOidIndex};
-char *Name_pg_cast_indices[Num_pg_cast_indices] =
-{CastOidIndex, CastSourceTargetIndex};
-char *Name_pg_class_indices[Num_pg_class_indices] =
-{ClassNameNspIndex, ClassOidIndex};
-char *Name_pg_constraint_indices[Num_pg_constraint_indices] =
-{ConstraintNameNspIndex, ConstraintOidIndex, ConstraintRelidIndex};
-char *Name_pg_conversion_indices[Num_pg_conversion_indices] =
-{ConversionDefaultIndex, ConversionNameNspIndex, ConversionOidIndex};
-char *Name_pg_database_indices[Num_pg_database_indices] =
-{DatabaseNameIndex, DatabaseOidIndex};
-char *Name_pg_depend_indices[Num_pg_depend_indices] =
-{DependDependerIndex, DependReferenceIndex};
-char *Name_pg_group_indices[Num_pg_group_indices] =
-{GroupNameIndex, GroupSysidIndex};
-char *Name_pg_index_indices[Num_pg_index_indices] =
-{IndexRelidIndex, IndexIndrelidIndex};
-char *Name_pg_inherits_indices[Num_pg_inherits_indices] =
-{InheritsRelidSeqnoIndex};
-char *Name_pg_language_indices[Num_pg_language_indices] =
-{LanguageOidIndex, LanguageNameIndex};
-char *Name_pg_largeobject_indices[Num_pg_largeobject_indices] =
-{LargeObjectLOidPNIndex};
-char *Name_pg_namespace_indices[Num_pg_namespace_indices] =
-{NamespaceNameIndex, NamespaceOidIndex};
-char *Name_pg_opclass_indices[Num_pg_opclass_indices] =
-{OpclassAmNameNspIndex, OpclassOidIndex};
-char *Name_pg_operator_indices[Num_pg_operator_indices] =
-{OperatorOidIndex, OperatorNameNspIndex};
-char *Name_pg_proc_indices[Num_pg_proc_indices] =
-{ProcedureOidIndex, ProcedureNameNspIndex};
-char *Name_pg_rewrite_indices[Num_pg_rewrite_indices] =
-{RewriteOidIndex, RewriteRelRulenameIndex};
-char *Name_pg_shadow_indices[Num_pg_shadow_indices] =
-{ShadowNameIndex, ShadowSysidIndex};
-char *Name_pg_statistic_indices[Num_pg_statistic_indices] =
-{StatisticRelidAttnumIndex};
-char *Name_pg_trigger_indices[Num_pg_trigger_indices] =
-{TriggerRelidNameIndex, TriggerConstrNameIndex, TriggerConstrRelidIndex, TriggerOidIndex};
-char *Name_pg_type_indices[Num_pg_type_indices] =
-{TypeNameNspIndex, TypeOidIndex};
-char *Name_pg_description_indices[Num_pg_description_indices] =
-{DescriptionObjIndex};
-
+#include "executor/executor.h"
/*
- * Changes (appends) to catalogs can and do happen at various places
- * throughout the code. We need a generic routine that will open all of
- * the indices defined on a given catalog and return the relation descriptors
- * associated with them.
+ * CatalogOpenIndexes - open the indexes on a system catalog.
+ *
+ * When inserting or updating tuples in a system catalog, call this
+ * to prepare to update the indexes for the catalog.
+ *
+ * In the current implementation, we share code for opening/closing the
+ * indexes with execUtils.c. But we do not use ExecInsertIndexTuples,
+ * because we don't want to create an EState. This implies that we
+ * do not support partial indexes on system catalogs. Nor do we handle
+ * functional indexes very well (the code will work, but will leak memory
+ * intraquery, because the index function is called in the per-query context
+ * that we are invoked in). This could be fixed with localized changes here
+ * if we wanted to pay the extra overhead of building an EState.
*/
-void
-CatalogOpenIndices(int nIndices, char **names, Relation *idescs)
+CatalogIndexState
+CatalogOpenIndexes(Relation heapRel)
{
- int i;
+ ResultRelInfo *resultRelInfo;
- if (IsIgnoringSystemIndexes())
- return;
- for (i = 0; i < nIndices; i++)
- idescs[i] = index_openr(names[i]);
+ resultRelInfo = makeNode(ResultRelInfo);
+ resultRelInfo->ri_RangeTableIndex = 1; /* dummy */
+ resultRelInfo->ri_RelationDesc = heapRel;
+ resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
+
+ ExecOpenIndices(resultRelInfo);
+
+ return resultRelInfo;
}
/*
- * This is the inverse routine to CatalogOpenIndices()
+ * CatalogCloseIndexes - clean up resources allocated by CatalogOpenIndexes
*/
void
-CatalogCloseIndices(int nIndices, Relation *idescs)
+CatalogCloseIndexes(CatalogIndexState indstate)
{
- int i;
-
- if (IsIgnoringSystemIndexes())
- return;
- for (i = 0; i < nIndices; i++)
- index_close(idescs[i]);
+ ExecCloseIndices(indstate);
+ pfree(indstate);
}
-
/*
- * For the same reasons outlined above for CatalogOpenIndices(), we need a
- * routine that takes a new catalog tuple and inserts an associated index
- * tuple into each catalog index.
+ * CatalogIndexInsert - insert index entries for one catalog tuple
*
- * NOTE: since this routine looks up all the pg_index data on each call,
- * it's relatively inefficient for inserting a large number of tuples into
- * the same catalog. We use it only for inserting one or a few tuples
- * in a given command. See ExecOpenIndices() and related routines if you
- * are inserting tuples in bulk.
+ * This should be called for each inserted or updated catalog tuple.
*
- * NOTE: we do not bother to handle partial indices. Nor do we try to
- * be efficient for functional indices (the code should work for them,
- * but may leak memory intraquery). This should be OK for system catalogs,
- * but don't use this routine for user tables!
+ * This is effectively a cut-down version of ExecInsertIndexTuples.
*/
void
-CatalogIndexInsert(Relation *idescs,
- int nIndices,
- Relation heapRelation,
- HeapTuple heapTuple)
+CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
{
+ int i;
+ int numIndexes;
+ RelationPtr relationDescs;
+ Relation heapRelation;
TupleDesc heapDescriptor;
+ IndexInfo **indexInfoArray;
Datum datum[INDEX_MAX_KEYS];
char nullv[INDEX_MAX_KEYS];
- int i;
- if (IsIgnoringSystemIndexes() || (!heapRelation->rd_rel->relhasindex))
- return;
+ /*
+ * Get information from the state structure.
+ */
+ numIndexes = indstate->ri_NumIndices;
+ relationDescs = indstate->ri_IndexRelationDescs;
+ indexInfoArray = indstate->ri_IndexRelationInfo;
+ heapRelation = indstate->ri_RelationDesc;
heapDescriptor = RelationGetDescr(heapRelation);
- for (i = 0; i < nIndices; i++)
+ /*
+ * for each index, form and insert the index tuple
+ */
+ for (i = 0; i < numIndexes; i++)
{
IndexInfo *indexInfo;
- InsertIndexResult indexRes;
+ InsertIndexResult result;
- indexInfo = BuildIndexInfo(idescs[i]->rd_index);
+ indexInfo = indexInfoArray[i];
+ /* Partial indexes on system catalogs are not supported */
+ Assert(indexInfo->ii_Predicate == NIL);
+
+ /*
+ * FormIndexDatum fills in its datum and null parameters with
+ * attribute information taken from the given heap tuple.
+ */
FormIndexDatum(indexInfo,
heapTuple,
heapDescriptor,
datum,
nullv);
- indexRes = index_insert(idescs[i], datum, nullv,
- &heapTuple->t_self, heapRelation,
- idescs[i]->rd_uniqueindex);
- if (indexRes)
- pfree(indexRes);
- pfree(indexInfo);
+ /*
+ * The index AM does the rest.
+ */
+ result = index_insert(relationDescs[i], /* index relation */
+ datum, /* array of heaptuple Datums */
+ nullv, /* info on nulls */
+ &(heapTuple->t_self), /* tid of heap tuple */
+ heapRelation,
+ relationDescs[i]->rd_uniqueindex);
+
+ if (result)
+ pfree(result);
}
}
+
+/*
+ * CatalogUpdateIndexes - do all the indexing work for a new catalog tuple
+ *
+ * This is a convenience routine for the common case where we only need
+ * to insert or update a single tuple in a system catalog. Avoid using it for
+ * multiple tuples, since opening the indexes and building the index info
+ * structures is moderately expensive.
+ */
+void
+CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple)
+{
+ CatalogIndexState indstate;
+
+ indstate = CatalogOpenIndexes(heapRel);
+ CatalogIndexInsert(indstate, heapTuple);
+ CatalogCloseIndexes(indstate);
+}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.52 2002/07/24 19:11:07 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.53 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
tup = heap_formtuple(tupDesc, values, nulls);
simple_heap_insert(aggdesc, tup);
- if (RelationGetForm(aggdesc)->relhasindex)
- {
- Relation idescs[Num_pg_aggregate_indices];
-
- CatalogOpenIndices(Num_pg_aggregate_indices, Name_pg_aggregate_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_aggregate_indices, aggdesc, tup);
- CatalogCloseIndices(Num_pg_aggregate_indices, idescs);
- }
+ CatalogUpdateIndexes(aggdesc, tup);
heap_close(aggdesc, RowExclusiveLock);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.3 2002/07/16 22:12:18 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_constraint.c,v 1.4 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
conOid = simple_heap_insert(conDesc, tup);
- /* Handle Indices */
- if (RelationGetForm(conDesc)->relhasindex)
- {
- Relation idescs[Num_pg_constraint_indices];
-
- CatalogOpenIndices(Num_pg_constraint_indices, Name_pg_constraint_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_constraint_indices, conDesc, tup);
- CatalogCloseIndices(Num_pg_constraint_indices, idescs);
- }
+ /* update catalog indexes */
+ CatalogUpdateIndexes(conDesc, tup);
conobject.classId = RelationGetRelid(conDesc);
conobject.objectId = conOid;
Relation pgrel;
HeapTuple relTup;
Form_pg_class classForm;
- Relation ridescs[Num_pg_class_indices];
pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
relTup = SearchSysCacheCopy(RELOID,
simple_heap_update(pgrel, &relTup->t_self, relTup);
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
- CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, relTup);
- CatalogCloseIndices(Num_pg_class_indices, ridescs);
+ CatalogUpdateIndexes(pgrel, relTup);
heap_freetuple(relTup);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.3 2002/07/25 10:07:10 ishii Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_conversion.c,v 1.4 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Assert(OidIsValid(oid));
/* update the index if any */
- if (RelationGetForm(rel)->relhasindex)
- {
- Relation idescs[Num_pg_conversion_indices];
-
- CatalogOpenIndices(Num_pg_conversion_indices, Name_pg_conversion_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_conversion_indices, rel, tup);
- CatalogCloseIndices(Num_pg_conversion_indices, idescs);
- }
+ CatalogUpdateIndexes(rel, tup);
myself.classId = get_system_catalog_relid(ConversionRelationName);
myself.objectId = HeapTupleGetOid(tup);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.3 2002/07/16 22:12:18 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_depend.c,v 1.4 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
DependencyType behavior)
{
Relation dependDesc;
+ CatalogIndexState indstate;
HeapTuple tup;
int i;
char nulls[Natts_pg_depend];
Datum values[Natts_pg_depend];
- Relation idescs[Num_pg_depend_indices];
- bool indices_opened = false;
if (nreferenced <= 0)
return; /* nothing to do */
dependDesc = heap_openr(DependRelationName, RowExclusiveLock);
+ /* Don't open indexes unless we need to make an update */
+ indstate = NULL;
+
memset(nulls, ' ', sizeof(nulls));
for (i = 0; i < nreferenced; i++, referenced++)
simple_heap_insert(dependDesc, tup);
- /*
- * Keep indices current
- */
- if (!indices_opened)
- {
- CatalogOpenIndices(Num_pg_depend_indices, Name_pg_depend_indices, idescs);
- indices_opened = true;
- }
- CatalogIndexInsert(idescs, Num_pg_depend_indices, dependDesc, tup);
+ /* keep indexes current */
+ if (indstate == NULL)
+ indstate = CatalogOpenIndexes(dependDesc);
+
+ CatalogIndexInsert(indstate, tup);
heap_freetuple(tup);
}
}
- if (indices_opened)
- CatalogCloseIndices(Num_pg_depend_indices, idescs);
+ if (indstate != NULL)
+ CatalogCloseIndexes(indstate);
heap_close(dependDesc, RowExclusiveLock);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.13 2002/06/20 20:29:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.14 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
Relation pg_largeobject;
HeapTuple ntup;
- Relation idescs[Num_pg_largeobject_indices];
Datum values[Natts_pg_largeobject];
char nulls[Natts_pg_largeobject];
int i;
*/
simple_heap_insert(pg_largeobject, ntup);
- /*
- * Update indices
- */
- if (!IsIgnoringSystemIndexes())
- {
- CatalogOpenIndices(Num_pg_largeobject_indices, Name_pg_largeobject_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_largeobject_indices, pg_largeobject, ntup);
- CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
- }
+ /* Update indexes */
+ CatalogUpdateIndexes(pg_largeobject, ntup);
heap_close(pg_largeobject, RowExclusiveLock);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.4 2002/06/20 20:29:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_namespace.c,v 1.5 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
tupDesc = nspdesc->rd_att;
tup = heap_formtuple(tupDesc, values, nulls);
+
nspoid = simple_heap_insert(nspdesc, tup);
Assert(OidIsValid(nspoid));
- if (RelationGetForm(nspdesc)->relhasindex)
- {
- Relation idescs[Num_pg_namespace_indices];
-
- CatalogOpenIndices(Num_pg_namespace_indices, Name_pg_namespace_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_namespace_indices, nspdesc, tup);
- CatalogCloseIndices(Num_pg_namespace_indices, idescs);
- }
+ CatalogUpdateIndexes(nspdesc, tup);
heap_close(nspdesc, RowExclusiveLock);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.74 2002/07/24 19:11:08 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.75 2002/08/05 03:29:16 tgl Exp $
*
* NOTES
* these routines moved here from commands/define.c and somewhat cleaned up.
*/
operatorObjectId = simple_heap_insert(pg_operator_desc, tup);
- if (RelationGetForm(pg_operator_desc)->relhasindex)
- {
- Relation idescs[Num_pg_operator_indices];
-
- CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
- CatalogCloseIndices(Num_pg_operator_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_operator_desc, tup);
/* Add dependencies for the entry */
makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc));
}
/* Must update the indexes in either case */
- if (RelationGetForm(pg_operator_desc)->relhasindex)
- {
- Relation idescs[Num_pg_operator_indices];
-
- CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
- CatalogCloseIndices(Num_pg_operator_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_operator_desc, tup);
/* Add dependencies for the entry */
makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc));
simple_heap_update(pg_operator_desc, &tup->t_self, tup);
- if (RelationGetForm(pg_operator_desc)->relhasindex)
- {
- Relation idescs[Num_pg_operator_indices];
-
- CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
- CatalogCloseIndices(Num_pg_operator_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_operator_desc, tup);
}
}
simple_heap_update(pg_operator_desc, &tup->t_self, tup);
- if (RelationGetForm(pg_operator_desc)->relhasindex)
- {
- Relation idescs[Num_pg_operator_indices];
-
- CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
- CatalogCloseIndices(Num_pg_operator_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_operator_desc, tup);
values[Anum_pg_operator_oprcom - 1] = (Datum) NULL;
replaces[Anum_pg_operator_oprcom - 1] = ' ';
simple_heap_update(pg_operator_desc, &tup->t_self, tup);
- if (RelationGetForm(pg_operator_desc)->relhasindex)
- {
- Relation idescs[Num_pg_operator_indices];
-
- CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
- CatalogCloseIndices(Num_pg_operator_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_operator_desc, tup);
}
heap_close(pg_operator_desc, RowExclusiveLock);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.87 2002/08/05 02:30:50 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.88 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
is_update = false;
}
- /* Need to update indices for either the insert or update case */
- if (RelationGetForm(rel)->relhasindex)
- {
- Relation idescs[Num_pg_proc_indices];
-
- CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_proc_indices, rel, tup);
- CatalogCloseIndices(Num_pg_proc_indices, idescs);
- }
+ /* Need to update indexes for either the insert or update case */
+ CatalogUpdateIndexes(rel, tup);
AssertTupleDescHasOid(tupDesc);
retval = HeapTupleGetOid(tup);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.76 2002/07/24 19:11:09 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.77 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
typoid = simple_heap_insert(pg_type_desc, tup);
- if (RelationGetForm(pg_type_desc)->relhasindex)
- {
- Relation idescs[Num_pg_type_indices];
-
- CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tup);
- CatalogCloseIndices(Num_pg_type_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_type_desc, tup);
/*
* clean up and return the type-oid
typeObjectId = simple_heap_insert(pg_type_desc, tup);
}
- /* Update indices (not necessary if bootstrapping) */
- if (RelationGetForm(pg_type_desc)->relhasindex)
- {
- Relation idescs[Num_pg_type_indices];
-
- CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tup);
- CatalogCloseIndices(Num_pg_type_indices, idescs);
- }
+ /* Update indexes */
+ CatalogUpdateIndexes(pg_type_desc, tup);
/*
* Create dependencies. We can/must skip this in bootstrap mode.
const char *newTypeName)
{
Relation pg_type_desc;
- Relation idescs[Num_pg_type_indices];
HeapTuple tuple;
pg_type_desc = heap_openr(TypeRelationName, RowExclusiveLock);
simple_heap_update(pg_type_desc, &tuple->t_self, tuple);
- /* update the system catalog indices */
- CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tuple);
- CatalogCloseIndices(Num_pg_type_indices, idescs);
+ /* update the system catalog indexes */
+ CatalogUpdateIndexes(pg_type_desc, tuple);
heap_freetuple(tuple);
heap_close(pg_type_desc, RowExclusiveLock);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.40 2002/08/02 18:15:05 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.41 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Datum values[Natts_pg_statistic];
char nulls[Natts_pg_statistic];
char replaces[Natts_pg_statistic];
- Relation irelations[Num_pg_statistic_indices];
/* Ignore attr if we weren't able to collect stats */
if (!stats->stats_valid)
simple_heap_insert(sd, stup);
}
- /* update indices too */
- CatalogOpenIndices(Num_pg_statistic_indices, Name_pg_statistic_indices,
- irelations);
- CatalogIndexInsert(irelations, Num_pg_statistic_indices, sd, stup);
- CatalogCloseIndices(Num_pg_statistic_indices, irelations);
+ /* update indexes too */
+ CatalogUpdateIndexes(sd, stup);
heap_freetuple(stup);
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.87 2002/06/20 20:29:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.88 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
simple_heap_insert(lRel, tuple);
#ifdef NOT_USED /* currently there are no indexes */
- if (RelationGetForm(lRel)->relhasindex)
- {
- Relation idescs[Num_pg_listener_indices];
-
- CatalogOpenIndices(Num_pg_listener_indices, Name_pg_listener_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, tuple);
- CatalogCloseIndices(Num_pg_listener_indices, idescs);
- }
+ CatalogUpdateIndexes(lRel, tuple);
#endif
heap_freetuple(tuple);
simple_heap_update(lRel, &lTuple->t_self, rTuple);
#ifdef NOT_USED /* currently there are no indexes */
- if (RelationGetForm(lRel)->relhasindex)
- {
- Relation idescs[Num_pg_listener_indices];
-
- CatalogOpenIndices(Num_pg_listener_indices, Name_pg_listener_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, rTuple);
- CatalogCloseIndices(Num_pg_listener_indices, idescs);
- }
+ CatalogUpdateIndexes(lRel, rTuple);
#endif
}
}
simple_heap_update(lRel, &lTuple->t_self, rTuple);
#ifdef NOT_USED /* currently there are no indexes */
- if (RelationGetForm(lRel)->relhasindex)
- {
- Relation idescs[Num_pg_listener_indices];
-
- CatalogOpenIndices(Num_pg_listener_indices, Name_pg_listener_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, rTuple);
- CatalogCloseIndices(Num_pg_listener_indices, idescs);
- }
+ CatalogUpdateIndexes(lRel, rTuple);
#endif
}
}
* Copyright (c) 1996-2001, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.54 2002/08/02 18:15:05 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.55 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
/* Update indexes, if necessary */
-
if (newtuple != NULL)
{
- if (RelationGetForm(description)->relhasindex)
- {
- Relation idescs[Num_pg_description_indices];
-
- CatalogOpenIndices(Num_pg_description_indices,
- Name_pg_description_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_description_indices, description,
- newtuple);
- CatalogCloseIndices(Num_pg_description_indices, idescs);
- }
+ CatalogUpdateIndexes(description, newtuple);
heap_freetuple(newtuple);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.97 2002/07/20 05:16:57 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.98 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
simple_heap_insert(pg_database_rel, tuple);
- /*
- * Update indexes
- */
- if (RelationGetForm(pg_database_rel)->relhasindex)
- {
- Relation idescs[Num_pg_database_indices];
-
- CatalogOpenIndices(Num_pg_database_indices,
- Name_pg_database_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_database_indices, pg_database_rel,
- tuple);
- CatalogCloseIndices(Num_pg_database_indices, idescs);
- }
+ /* Update indexes */
+ CatalogUpdateIndexes(pg_database_rel, tuple);
/* Close pg_database, but keep lock till commit */
heap_close(pg_database_rel, NoLock);
newtuple = heap_modifytuple(tuple, rel, repl_val, repl_null, repl_repl);
simple_heap_update(rel, &tuple->t_self, newtuple);
- /*
- * Update indexes
- */
- if (RelationGetForm(rel)->relhasindex)
- {
- Relation idescs[Num_pg_database_indices];
-
- CatalogOpenIndices(Num_pg_database_indices,
- Name_pg_database_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_database_indices, rel,
- newtuple);
- CatalogCloseIndices(Num_pg_database_indices, idescs);
- }
+ /* Update indexes */
+ CatalogUpdateIndexes(rel, newtuple);
heap_endscan(scan);
heap_close(rel, RowExclusiveLock);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.15 2002/07/29 23:44:44 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.16 2002/08/05 03:29:16 tgl Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
nulls[i] = ' ';
tuple = heap_formtuple(RelationGetDescr(relation), values, nulls);
- simple_heap_insert(relation, tuple);
- if (RelationGetForm(relation)->relhasindex)
- {
- Relation idescs[Num_pg_cast_indices];
+ simple_heap_insert(relation, tuple);
- CatalogOpenIndices(Num_pg_cast_indices, Name_pg_cast_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_cast_indices, relation, tuple);
- CatalogCloseIndices(Num_pg_cast_indices, idescs);
- }
+ CatalogUpdateIndexes(relation, tuple);
myself.classId = RelationGetRelid(relation);
myself.objectId = HeapTupleGetOid(tuple);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.2 2002/07/29 23:46:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.3 2002/08/05 03:29:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
opclassoid = simple_heap_insert(rel, tup);
- if (RelationGetForm(rel)->relhasindex)
- {
- Relation idescs[Num_pg_opclass_indices];
-
- CatalogOpenIndices(Num_pg_opclass_indices, Name_pg_opclass_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_opclass_indices, rel, tup);
- CatalogCloseIndices(Num_pg_opclass_indices, idescs);
- }
+ CatalogUpdateIndexes(rel, tup);
heap_freetuple(tup);
simple_heap_insert(rel, tup);
- if (RelationGetForm(rel)->relhasindex)
- {
- Relation idescs[Num_pg_amop_indices];
+ CatalogUpdateIndexes(rel, tup);
- CatalogOpenIndices(Num_pg_amop_indices, Name_pg_amop_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_amop_indices, rel, tup);
- CatalogCloseIndices(Num_pg_amop_indices, idescs);
- }
heap_freetuple(tup);
}
simple_heap_insert(rel, tup);
- if (RelationGetForm(rel)->relhasindex)
- {
- Relation idescs[Num_pg_amproc_indices];
+ CatalogUpdateIndexes(rel, tup);
- CatalogOpenIndices(Num_pg_amproc_indices, Name_pg_amproc_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_amproc_indices, rel, tup);
- CatalogCloseIndices(Num_pg_amproc_indices, idescs);
- }
heap_freetuple(tup);
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.38 2002/07/24 19:11:09 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.39 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
simple_heap_insert(rel, tup);
- if (RelationGetForm(rel)->relhasindex)
- {
- Relation idescs[Num_pg_language_indices];
-
- CatalogOpenIndices(Num_pg_language_indices, Name_pg_language_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_language_indices, rel, tup);
- CatalogCloseIndices(Num_pg_language_indices, idescs);
- }
+ CatalogUpdateIndexes(rel, tup);
/*
* Create dependencies for language
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.26 2002/08/02 18:15:06 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v 1.27 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* BadArg if name is invalid
*
* Note:
- * Rows are removed, indices are truncated and reconstructed.
+ * Rows are removed, indexes are truncated and reconstructed.
*/
void
TruncateRelation(const RangeVar *relation)
simple_heap_insert(relation, tuple);
- if (RelationGetForm(relation)->relhasindex)
- {
- Relation idescs[Num_pg_inherits_indices];
-
- CatalogOpenIndices(Num_pg_inherits_indices, Name_pg_inherits_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_inherits_indices, relation, tuple);
- CatalogCloseIndices(Num_pg_inherits_indices, idescs);
- }
+ CatalogUpdateIndexes(relation, tuple);
heap_freetuple(tuple);
{
Relation relationRelation;
HeapTuple tuple;
- Relation idescs[Num_pg_class_indices];
/*
* Fetch a modifiable copy of the tuple, modify it, update pg_class.
((Form_pg_class) GETSTRUCT(tuple))->relhassubclass = relhassubclass;
simple_heap_update(relationRelation, &tuple->t_self, tuple);
- /* keep the catalog indices up to date */
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
+ /* keep the catalog indexes up to date */
+ CatalogUpdateIndexes(relationRelation, tuple);
heap_freetuple(tuple);
heap_close(relationRelation, RowExclusiveLock);
simple_heap_update(attrelation, &atttup->t_self, atttup);
- /* keep system catalog indices current */
- {
- Relation irelations[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
- CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, atttup);
- CatalogCloseIndices(Num_pg_attr_indices, irelations);
- }
+ /* keep system catalog indexes current */
+ CatalogUpdateIndexes(attrelation, atttup);
heap_freetuple(atttup);
simple_heap_update(attrelation, &atttup->t_self, atttup);
- /* keep system catalog indices current */
- {
- Relation irelations[Num_pg_attr_indices];
+ /* keep system catalog indexes current */
+ CatalogUpdateIndexes(attrelation, atttup);
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
- CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, atttup);
- CatalogCloseIndices(Num_pg_attr_indices, irelations);
- }
heap_freetuple(atttup);
}
char *oldrelname;
char relkind;
bool relhastriggers;
- Relation irelations[Num_pg_class_indices];
/*
* Grab an exclusive lock on the target table or index, which we will
simple_heap_update(relrelation, &reltup->t_self, reltup);
- /* keep the system catalog indices current */
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, irelations);
- CatalogIndexInsert(irelations, Num_pg_class_indices, relrelation, reltup);
- CatalogCloseIndices(Num_pg_class_indices, irelations);
+ /* keep the system catalog indexes current */
+ CatalogUpdateIndexes(relrelation, reltup);
heap_close(relrelation, NoLock);
heap_freetuple(reltup);
*/
simple_heap_update(tgrel, &tuple->t_self, tuple);
- {
- Relation irelations[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, irelations);
- CatalogIndexInsert(irelations, Num_pg_trigger_indices, tgrel, tuple);
- CatalogCloseIndices(Num_pg_trigger_indices, irelations);
- }
+ CatalogUpdateIndexes(tgrel, tuple);
/* free up our scratch memory */
pfree(newtgargs);
simple_heap_insert(attrdesc, attributeTuple);
/* Update indexes on pg_attribute */
- if (RelationGetForm(attrdesc)->relhasindex)
- {
- Relation idescs[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_attr_indices, attrdesc, attributeTuple);
- CatalogCloseIndices(Num_pg_attr_indices, idescs);
- }
+ CatalogUpdateIndexes(attrdesc, attributeTuple);
heap_close(attrdesc, RowExclusiveLock);
AssertTupleDescHasOid(pgclass->rd_att);
simple_heap_update(pgclass, &newreltup->t_self, newreltup);
- /* keep catalog indices current */
- if (RelationGetForm(pgclass)->relhasindex)
- {
- Relation ridescs[Num_pg_class_indices];
-
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
- CatalogIndexInsert(ridescs, Num_pg_class_indices, pgclass, newreltup);
- CatalogCloseIndices(Num_pg_class_indices, ridescs);
- }
+ /* keep catalog indexes current */
+ CatalogUpdateIndexes(pgclass, newreltup);
heap_freetuple(newreltup);
ReleaseSysCache(reltup);
* Check that the attribute is not in a primary key
*/
- /* Loop over all indices on the relation */
+ /* Loop over all indexes on the relation */
indexoidlist = RelationGetIndexList(rel);
foreach(indexoidscan, indexoidlist)
simple_heap_update(attr_rel, &tuple->t_self, tuple);
- /* keep the system catalog indices current */
- if (RelationGetForm(attr_rel)->relhasindex)
- {
- Relation idescs[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
- CatalogCloseIndices(Num_pg_attr_indices, idescs);
- }
+ /* keep the system catalog indexes current */
+ CatalogUpdateIndexes(attr_rel, tuple);
heap_close(attr_rel, RowExclusiveLock);
simple_heap_update(attr_rel, &tuple->t_self, tuple);
- /* keep the system catalog indices current */
- if (RelationGetForm(attr_rel)->relhasindex)
- {
- Relation idescs[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
- CatalogCloseIndices(Num_pg_attr_indices, idescs);
- }
+ /* keep the system catalog indexes current */
+ CatalogUpdateIndexes(attr_rel, tuple);
heap_close(attr_rel, RowExclusiveLock);
simple_heap_update(attrelation, &tuple->t_self, tuple);
- /* keep system catalog indices current */
- {
- Relation irelations[Num_pg_attr_indices];
-
- CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
- CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, tuple);
- CatalogCloseIndices(Num_pg_attr_indices, irelations);
- }
+ /* keep system catalog indexes current */
+ CatalogUpdateIndexes(attrelation, tuple);
heap_freetuple(tuple);
+
heap_close(attrelation, NoLock);
heap_close(rel, NoLock); /* close rel, but keep lock! */
}
Relation target_rel;
Relation class_rel;
HeapTuple tuple;
- Relation idescs[Num_pg_class_indices];
Form_pg_class tuple_class;
/* Get exclusive lock till end of transaction on the target table */
tuple_class->relowner = newOwnerSysId;
simple_heap_update(class_rel, &tuple->t_self, tuple);
- /* Keep the catalog indices up to date */
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, class_rel, tuple);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
+ /* Keep the catalog indexes up to date */
+ CatalogUpdateIndexes(class_rel, tuple);
/*
* If we are operating on a table, also change the ownership of any
bool shared_relation;
Relation class_rel;
Buffer buffer;
- Relation ridescs[Num_pg_class_indices];
Oid toast_relid;
Oid toast_idxid;
char toast_relname[NAMEDATALEN];
* Store the toast table's OID in the parent relation's tuple
*/
((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid = toast_relid;
+
simple_heap_update(class_rel, &reltup->t_self, reltup);
- /*
- * Keep catalog indices current
- */
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
- CatalogIndexInsert(ridescs, Num_pg_class_indices, class_rel, reltup);
- CatalogCloseIndices(Num_pg_class_indices, ridescs);
+ /* Keep catalog indexes current */
+ CatalogUpdateIndexes(class_rel, reltup);
heap_freetuple(reltup);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.123 2002/07/20 19:55:38 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.124 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
ScanKeyData key;
Relation pgrel;
HeapTuple tuple;
- Relation idescs[Num_pg_trigger_indices];
- Relation ridescs[Num_pg_class_indices];
Oid fargtypes[FUNC_MAX_ARGS];
Oid funcoid;
Oid funclang;
*/
simple_heap_insert(tgrel, tuple);
- CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);
- CatalogCloseIndices(Num_pg_trigger_indices, idescs);
+ CatalogUpdateIndexes(tgrel, tuple);
myself.classId = RelationGetRelid(tgrel);
myself.objectId = trigoid;
simple_heap_update(pgrel, &tuple->t_self, tuple);
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
- CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
- CatalogCloseIndices(Num_pg_class_indices, ridescs);
+ CatalogUpdateIndexes(pgrel, tuple);
heap_freetuple(tuple);
heap_close(pgrel, RowExclusiveLock);
Relation pgrel;
HeapTuple tuple;
Form_pg_class classForm;
- Relation ridescs[Num_pg_class_indices];
tgrel = heap_openr(TriggerRelationName, RowExclusiveLock);
simple_heap_update(pgrel, &tuple->t_self, tuple);
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
- CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
- CatalogCloseIndices(Num_pg_class_indices, ridescs);
+ CatalogUpdateIndexes(pgrel, tuple);
heap_freetuple(tuple);
HeapTuple tuple;
SysScanDesc tgscan;
ScanKeyData key[2];
- Relation idescs[Num_pg_trigger_indices];
/*
* Grab an exclusive lock on the target table, which we will NOT
simple_heap_update(tgrel, &tuple->t_self, tuple);
- /*
- * keep system catalog indices current
- */
- CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);
- CatalogCloseIndices(Num_pg_trigger_indices, idescs);
+ /* keep system catalog indexes current */
+ CatalogUpdateIndexes(tgrel, tuple);
/*
* Invalidate relation's relcache entry so that other backends (and
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.106 2002/07/24 19:11:09 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.107 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
simple_heap_insert(pg_shadow_rel, tuple);
- /*
- * Update indexes
- */
- if (RelationGetForm(pg_shadow_rel)->relhasindex)
- {
- Relation idescs[Num_pg_shadow_indices];
-
- CatalogOpenIndices(Num_pg_shadow_indices,
- Name_pg_shadow_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_shadow_indices, pg_shadow_rel,
- tuple);
- CatalogCloseIndices(Num_pg_shadow_indices, idescs);
- }
+ /* Update indexes */
+ CatalogUpdateIndexes(pg_shadow_rel, tuple);
/*
* Add the user to the groups specified. We'll just call the below
simple_heap_update(pg_shadow_rel, &tuple->t_self, new_tuple);
/* Update indexes */
- if (RelationGetForm(pg_shadow_rel)->relhasindex)
- {
- Relation idescs[Num_pg_shadow_indices];
-
- CatalogOpenIndices(Num_pg_shadow_indices,
- Name_pg_shadow_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_shadow_indices, pg_shadow_rel,
- new_tuple);
- CatalogCloseIndices(Num_pg_shadow_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_shadow_rel, new_tuple);
ReleaseSysCache(tuple);
heap_freetuple(new_tuple);
newtuple = heap_modifytuple(oldtuple, rel, repl_val, repl_null, repl_repl);
simple_heap_update(rel, &oldtuple->t_self, newtuple);
- {
- Relation idescs[Num_pg_shadow_indices];
-
- CatalogOpenIndices(Num_pg_shadow_indices, Name_pg_shadow_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_shadow_indices, rel, newtuple);
- CatalogCloseIndices(Num_pg_shadow_indices, idescs);
- }
+ CatalogUpdateIndexes(rel, newtuple);
ReleaseSysCache(oldtuple);
heap_close(rel, RowExclusiveLock);
*/
simple_heap_insert(pg_group_rel, tuple);
- /*
- * Update indexes
- */
- if (RelationGetForm(pg_group_rel)->relhasindex)
- {
- Relation idescs[Num_pg_group_indices];
-
- CatalogOpenIndices(Num_pg_group_indices,
- Name_pg_group_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_group_indices, pg_group_rel,
- tuple);
- CatalogCloseIndices(Num_pg_group_indices, idescs);
- }
+ /* Update indexes */
+ CatalogUpdateIndexes(pg_group_rel, tuple);
heap_close(pg_group_rel, NoLock);
simple_heap_update(group_rel, &group_tuple->t_self, tuple);
/* Update indexes */
- if (RelationGetForm(group_rel)->relhasindex)
- {
- Relation idescs[Num_pg_group_indices];
-
- CatalogOpenIndices(Num_pg_group_indices,
- Name_pg_group_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_group_indices, group_rel,
- tuple);
- CatalogCloseIndices(Num_pg_group_indices, idescs);
- }
+ CatalogUpdateIndexes(group_rel, tuple);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.76 2002/08/02 18:15:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.77 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
rewriteObjectId = simple_heap_insert(pg_rewrite_desc, tup);
- if (RelationGetForm(pg_rewrite_desc)->relhasindex)
- {
- Relation idescs[Num_pg_rewrite_indices];
-
- CatalogOpenIndices(Num_pg_rewrite_indices, Name_pg_rewrite_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_rewrite_indices, pg_rewrite_desc,
- tup);
- CatalogCloseIndices(Num_pg_rewrite_indices, idescs);
- }
+ CatalogUpdateIndexes(pg_rewrite_desc, tup);
heap_freetuple(tup);
simple_heap_update(pg_rewrite_desc, &ruletup->t_self, ruletup);
- /* keep system catalog indices current */
- if (RelationGetForm(pg_rewrite_desc)->relhasindex)
- {
- Relation idescs[Num_pg_rewrite_indices];
-
- CatalogOpenIndices(Num_pg_rewrite_indices, Name_pg_rewrite_indices,
- idescs);
- CatalogIndexInsert(idescs, Num_pg_rewrite_indices, pg_rewrite_desc,
- ruletup);
- CatalogCloseIndices(Num_pg_rewrite_indices, idescs);
- }
+ /* keep system catalog indexes current */
+ CatalogUpdateIndexes(pg_rewrite_desc, ruletup);
heap_freetuple(ruletup);
heap_close(pg_rewrite_desc, RowExclusiveLock);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.53 2002/07/12 18:43:17 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteSupport.c,v 1.54 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Relation relationRelation;
HeapTuple tuple;
Form_pg_class classForm;
- Relation idescs[Num_pg_class_indices];
/*
* Find the tuple to update in pg_class, using syscache for the
simple_heap_update(relationRelation, &tuple->t_self, tuple);
- /* Keep the catalog indices up to date */
- CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
- CatalogCloseIndices(Num_pg_class_indices, idescs);
+ /* Keep the catalog indexes up to date */
+ CatalogUpdateIndexes(relationRelation, tuple);
}
else
{
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.93 2002/06/20 20:29:35 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.94 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Datum values[Natts_pg_largeobject];
char nulls[Natts_pg_largeobject];
char replace[Natts_pg_largeobject];
- bool write_indices;
- Relation idescs[Num_pg_largeobject_indices];
+ CatalogIndexState indstate;
Assert(PointerIsValid(obj_desc));
Assert(buf != NULL);
if (nbytes <= 0)
return 0;
- write_indices = !IsIgnoringSystemIndexes();
- if (write_indices)
- CatalogOpenIndices(Num_pg_largeobject_indices,
- Name_pg_largeobject_indices,
- idescs);
+ indstate = CatalogOpenIndexes(obj_desc->heap_r);
ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0,
newtup = heap_modifytuple(oldtuple, obj_desc->heap_r,
values, nulls, replace);
simple_heap_update(obj_desc->heap_r, &newtup->t_self, newtup);
- if (write_indices)
- CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
- obj_desc->heap_r, newtup);
+ CatalogIndexInsert(indstate, newtup);
heap_freetuple(newtup);
/*
values[Anum_pg_largeobject_data - 1] = PointerGetDatum(&workbuf);
newtup = heap_formtuple(obj_desc->heap_r->rd_att, values, nulls);
simple_heap_insert(obj_desc->heap_r, newtup);
- if (write_indices)
- CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
- obj_desc->heap_r, newtup);
+ CatalogIndexInsert(indstate, newtup);
heap_freetuple(newtup);
}
pageno++;
index_endscan(sd);
- if (write_indices)
- CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
+ CatalogCloseIndexes(indstate);
/*
* Advance command counter so that my tuple updates will be seen by
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.49 2002/07/24 19:11:11 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/sets.c,v 1.50 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
AssertTupleDescHasOid(procrel->rd_att);
setoid = HeapTupleGetOid(newtup);
- if (RelationGetForm(procrel)->relhasindex)
- {
- Relation idescs[Num_pg_proc_indices];
+ CatalogUpdateIndexes(procrel, newtup);
- CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices, idescs);
- CatalogIndexInsert(idescs, Num_pg_proc_indices, procrel, newtup);
- CatalogCloseIndices(Num_pg_proc_indices, idescs);
- }
heap_freetuple(newtup);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.85 2002/08/02 18:15:08 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.86 2002/08/05 03:29:17 tgl Exp $
*
* NOTES
* These routines allow the parser/planner/executor to perform
This is used by CatalogCacheFlushRelation() to remove the correct
tuples during a table drop or relcache invalidation event.
- In include/catalog/indexing.h, add a define for the number of indexes
- on the relation, add define(s) for the index name(s), add an extern
- array to hold the index names, and use DECLARE_UNIQUE_INDEX to define
- the index. Cache lookups return only one row, so the index should be
- unique in most cases.
-
- In backend/catalog/indexing.c, initialize the relation array with
- the index names for the relation.
+ There must be a unique index underlying each syscache (ie, an index
+ whose key is the same as that of the cache). If there is not one
+ already, add definitions for it to include/catalog/indexing.h: you
+ need a #define for the index name and a DECLARE_UNIQUE_INDEX macro
+ with the actual declaration. (This will require a catversion.h update,
+ while simply adding/deleting caches only requires a recompile.)
Finally, any place your relation gets heap_insert() or
- heap_update calls, include code to do a CatalogIndexInsert() to update
- the system indexes. The heap_* calls do not update indexes.
+ heap_update calls, make sure there is a CatalogUpdateIndexes() or
+ similar call. The heap_* calls do not update indexes.
bjm 1999/11/22
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: indexing.h,v 1.73 2002/07/25 10:07:12 ishii Exp $
+ * $Id: indexing.h,v 1.74 2002/08/05 03:29:17 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "access/htup.h"
/*
- * Number of indices that exist for each system catalog
- */
-#define Num_pg_aggregate_indices 1
-#define Num_pg_am_indices 2
-#define Num_pg_amop_indices 2
-#define Num_pg_amproc_indices 1
-#define Num_pg_attr_indices 2
-#define Num_pg_attrdef_indices 2
-#define Num_pg_cast_indices 2
-#define Num_pg_class_indices 2
-#define Num_pg_constraint_indices 3
-#define Num_pg_conversion_indices 3
-#define Num_pg_database_indices 2
-#define Num_pg_depend_indices 2
-#define Num_pg_description_indices 1
-#define Num_pg_group_indices 2
-#define Num_pg_index_indices 2
-#define Num_pg_inherits_indices 1
-#define Num_pg_language_indices 2
-#define Num_pg_largeobject_indices 1
-#define Num_pg_namespace_indices 2
-#define Num_pg_opclass_indices 2
-#define Num_pg_operator_indices 2
-#define Num_pg_proc_indices 2
-#define Num_pg_rewrite_indices 2
-#define Num_pg_shadow_indices 2
-#define Num_pg_statistic_indices 1
-#define Num_pg_trigger_indices 4
-#define Num_pg_type_indices 2
-
-/*
- * Names of indices on system catalogs
+ * Names of indexes on system catalogs
+ *
+ * References to specific system indexes in the C code should use these
+ * macros rather than hardwiring the actual index name.
*/
#define AccessMethodOperatorIndex "pg_amop_opc_opr_index"
#define AccessMethodStrategyIndex "pg_amop_opc_strategy_index"
#define TypeNameNspIndex "pg_type_typname_nsp_index"
#define TypeOidIndex "pg_type_oid_index"
-/* Arrays of names of indices for each system catalog */
-extern char *Name_pg_aggregate_indices[];
-extern char *Name_pg_am_indices[];
-extern char *Name_pg_amop_indices[];
-extern char *Name_pg_amproc_indices[];
-extern char *Name_pg_attr_indices[];
-extern char *Name_pg_attrdef_indices[];
-extern char *Name_pg_cast_indices[];
-extern char *Name_pg_class_indices[];
-extern char *Name_pg_constraint_indices[];
-extern char *Name_pg_conversion_indices[];
-extern char *Name_pg_database_indices[];
-extern char *Name_pg_depend_indices[];
-extern char *Name_pg_description_indices[];
-extern char *Name_pg_group_indices[];
-extern char *Name_pg_index_indices[];
-extern char *Name_pg_inherits_indices[];
-extern char *Name_pg_language_indices[];
-extern char *Name_pg_largeobject_indices[];
-extern char *Name_pg_namespace_indices[];
-extern char *Name_pg_opclass_indices[];
-extern char *Name_pg_operator_indices[];
-extern char *Name_pg_proc_indices[];
-extern char *Name_pg_rewrite_indices[];
-extern char *Name_pg_shadow_indices[];
-extern char *Name_pg_statistic_indices[];
-extern char *Name_pg_trigger_indices[];
-extern char *Name_pg_type_indices[];
+/*
+ * The state object used by CatalogOpenIndexes and friends is actually the
+ * same as the executor's ResultRelInfo, but we give it another type name
+ * to decouple callers from that fact.
+ */
+typedef struct ResultRelInfo *CatalogIndexState;
/*
* indexing.c prototypes
*/
-extern void CatalogOpenIndices(int nIndices, char **names, Relation *idescs);
-extern void CatalogCloseIndices(int nIndices, Relation *idescs);
-extern void CatalogIndexInsert(Relation *idescs, int nIndices,
- Relation heapRelation, HeapTuple heapTuple);
+extern CatalogIndexState CatalogOpenIndexes(Relation heapRel);
+extern void CatalogCloseIndexes(CatalogIndexState indstate);
+extern void CatalogIndexInsert(CatalogIndexState indstate,
+ HeapTuple heapTuple);
+extern void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple);
/*
DECLARE_UNIQUE_INDEX(pg_type_oid_index on pg_type using btree(oid oid_ops));
DECLARE_UNIQUE_INDEX(pg_type_typname_nsp_index on pg_type using btree(typname name_ops, typnamespace oid_ops));
-/* last step of initialization script: build the indices declared above */
+/* last step of initialization script: build the indexes declared above */
BUILD_INDICES
#endif /* INDEXING_H */