Commit 15fe086f authored by Tom Lane's avatar Tom Lane

Restructure system-catalog index updating logic. Instead of having

hardwired lists of index names for each catalog, use the relcache's
mechanism for caching lists of OIDs of indexes of any table.  This
reduces the common case of updating system catalog indexes to a single
line, makes it much easier to add a new system index (in fact, you
can now do so on-the-fly if you want to), and as a nice side benefit
improves performance a little.  Per recent pghackers discussion.
parent 07f9682d
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* See acl.h. * See acl.h.
...@@ -236,15 +236,8 @@ ExecuteGrantStmt_Relation(GrantStmt *stmt) ...@@ -236,15 +236,8 @@ ExecuteGrantStmt_Relation(GrantStmt *stmt)
simple_heap_update(relation, &newtuple->t_self, newtuple); simple_heap_update(relation, &newtuple->t_self, newtuple);
{
/* keep the catalog indexes up to date */ /* keep the catalog indexes up to date */
Relation idescs[Num_pg_class_indices]; CatalogUpdateIndexes(relation, newtuple);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
idescs);
CatalogIndexInsert(idescs, Num_pg_class_indices, relation, newtuple);
CatalogCloseIndices(Num_pg_class_indices, idescs);
}
pfree(old_acl); pfree(old_acl);
pfree(new_acl); pfree(new_acl);
...@@ -332,15 +325,8 @@ ExecuteGrantStmt_Database(GrantStmt *stmt) ...@@ -332,15 +325,8 @@ ExecuteGrantStmt_Database(GrantStmt *stmt)
simple_heap_update(relation, &newtuple->t_self, newtuple); simple_heap_update(relation, &newtuple->t_self, newtuple);
{
/* keep the catalog indexes up to date */ /* keep the catalog indexes up to date */
Relation idescs[Num_pg_database_indices]; CatalogUpdateIndexes(relation, newtuple);
CatalogOpenIndices(Num_pg_database_indices, Name_pg_database_indices,
idescs);
CatalogIndexInsert(idescs, Num_pg_database_indices, relation, newtuple);
CatalogCloseIndices(Num_pg_database_indices, idescs);
}
pfree(old_acl); pfree(old_acl);
pfree(new_acl); pfree(new_acl);
...@@ -434,15 +420,8 @@ ExecuteGrantStmt_Function(GrantStmt *stmt) ...@@ -434,15 +420,8 @@ ExecuteGrantStmt_Function(GrantStmt *stmt)
simple_heap_update(relation, &newtuple->t_self, newtuple); simple_heap_update(relation, &newtuple->t_self, newtuple);
{
/* keep the catalog indexes up to date */ /* keep the catalog indexes up to date */
Relation idescs[Num_pg_proc_indices]; CatalogUpdateIndexes(relation, newtuple);
CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices,
idescs);
CatalogIndexInsert(idescs, Num_pg_proc_indices, relation, newtuple);
CatalogCloseIndices(Num_pg_proc_indices, idescs);
}
pfree(old_acl); pfree(old_acl);
pfree(new_acl); pfree(new_acl);
...@@ -531,15 +510,8 @@ ExecuteGrantStmt_Language(GrantStmt *stmt) ...@@ -531,15 +510,8 @@ ExecuteGrantStmt_Language(GrantStmt *stmt)
simple_heap_update(relation, &newtuple->t_self, newtuple); simple_heap_update(relation, &newtuple->t_self, newtuple);
{
/* keep the catalog indexes up to date */ /* keep the catalog indexes up to date */
Relation idescs[Num_pg_language_indices]; CatalogUpdateIndexes(relation, newtuple);
CatalogOpenIndices(Num_pg_language_indices, Name_pg_language_indices,
idescs);
CatalogIndexInsert(idescs, Num_pg_language_indices, relation, newtuple);
CatalogCloseIndices(Num_pg_language_indices, idescs);
}
pfree(old_acl); pfree(old_acl);
pfree(new_acl); pfree(new_acl);
...@@ -628,15 +600,8 @@ ExecuteGrantStmt_Namespace(GrantStmt *stmt) ...@@ -628,15 +600,8 @@ ExecuteGrantStmt_Namespace(GrantStmt *stmt)
simple_heap_update(relation, &newtuple->t_self, newtuple); simple_heap_update(relation, &newtuple->t_self, newtuple);
{
/* keep the catalog indexes up to date */ /* keep the catalog indexes up to date */
Relation idescs[Num_pg_namespace_indices]; CatalogUpdateIndexes(relation, newtuple);
CatalogOpenIndices(Num_pg_namespace_indices, Name_pg_namespace_indices,
idescs);
CatalogIndexInsert(idescs, Num_pg_namespace_indices, relation, newtuple);
CatalogCloseIndices(Num_pg_namespace_indices, idescs);
}
pfree(old_acl); pfree(old_acl);
pfree(new_acl); pfree(new_acl);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * INTERFACE ROUTINES
...@@ -423,23 +423,17 @@ AddNewAttributeTuples(Oid new_rel_oid, ...@@ -423,23 +423,17 @@ AddNewAttributeTuples(Oid new_rel_oid,
int i; int i;
HeapTuple tup; HeapTuple tup;
Relation rel; Relation rel;
bool hasindex; CatalogIndexState indstate;
Relation idescs[Num_pg_attr_indices];
int natts = tupdesc->natts; int natts = tupdesc->natts;
ObjectAddress myself, ObjectAddress myself,
referenced; referenced;
/* /*
* open pg_attribute * open pg_attribute and its indexes.
*/ */
rel = heap_openr(AttributeRelationName, RowExclusiveLock); rel = heap_openr(AttributeRelationName, RowExclusiveLock);
/* indstate = CatalogOpenIndexes(rel);
* 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);
/* /*
* First we add the user attributes. This is also a convenient place * First we add the user attributes. This is also a convenient place
...@@ -461,8 +455,7 @@ AddNewAttributeTuples(Oid new_rel_oid, ...@@ -461,8 +455,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
simple_heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (hasindex) CatalogIndexInsert(indstate, tup);
CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
heap_freetuple(tup); heap_freetuple(tup);
...@@ -509,8 +502,7 @@ AddNewAttributeTuples(Oid new_rel_oid, ...@@ -509,8 +502,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
simple_heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (hasindex) CatalogIndexInsert(indstate, tup);
CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
heap_freetuple(tup); heap_freetuple(tup);
} }
...@@ -521,8 +513,7 @@ AddNewAttributeTuples(Oid new_rel_oid, ...@@ -521,8 +513,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
/* /*
* clean up * clean up
*/ */
if (hasindex) CatalogCloseIndexes(indstate);
CatalogCloseIndices(Num_pg_attr_indices, idescs);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
} }
...@@ -543,7 +534,6 @@ AddNewRelationTuple(Relation pg_class_desc, ...@@ -543,7 +534,6 @@ AddNewRelationTuple(Relation pg_class_desc,
{ {
Form_pg_class new_rel_reltup; Form_pg_class new_rel_reltup;
HeapTuple tup; HeapTuple tup;
Relation idescs[Num_pg_class_indices];
/* /*
* first we update some of the information in our uncataloged * first we update some of the information in our uncataloged
...@@ -606,20 +596,11 @@ AddNewRelationTuple(Relation pg_class_desc, ...@@ -606,20 +596,11 @@ AddNewRelationTuple(Relation pg_class_desc,
HeapTupleSetOid(tup, new_rel_oid); 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); simple_heap_insert(pg_class_desc, tup);
if (!IsIgnoringSystemIndexes()) CatalogUpdateIndexes(pg_class_desc, tup);
{
/*
* 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);
}
heap_freetuple(tup); heap_freetuple(tup);
} }
...@@ -953,15 +934,8 @@ RemoveAttributeById(Oid relid, AttrNumber attnum) ...@@ -953,15 +934,8 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
simple_heap_update(attr_rel, &tuple->t_self, tuple); simple_heap_update(attr_rel, &tuple->t_self, tuple);
/* keep the system catalog indices current */ /* keep the system catalog indexes current */
if (RelationGetForm(attr_rel)->relhasindex) CatalogUpdateIndexes(attr_rel, tuple);
{
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);
}
/* /*
* Because updating the pg_attribute row will trigger a relcache flush * Because updating the pg_attribute row will trigger a relcache flush
...@@ -1087,15 +1061,8 @@ RemoveAttrDefaultById(Oid attrdefId) ...@@ -1087,15 +1061,8 @@ RemoveAttrDefaultById(Oid attrdefId)
simple_heap_update(attr_rel, &tuple->t_self, tuple); simple_heap_update(attr_rel, &tuple->t_self, tuple);
/* keep the system catalog indices current */ /* keep the system catalog indexes current */
if (RelationGetForm(attr_rel)->relhasindex) CatalogUpdateIndexes(attr_rel, tuple);
{
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);
}
/* /*
* Our update of the pg_attribute row will force a relcache rebuild, * Our update of the pg_attribute row will force a relcache rebuild,
...@@ -1195,12 +1162,10 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin) ...@@ -1195,12 +1162,10 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
Node *expr; Node *expr;
char *adsrc; char *adsrc;
Relation adrel; Relation adrel;
Relation idescs[Num_pg_attrdef_indices];
HeapTuple tuple; HeapTuple tuple;
Datum values[4]; Datum values[4];
static char nulls[4] = {' ', ' ', ' ', ' '}; static char nulls[4] = {' ', ' ', ' ', ' '};
Relation attrrel; Relation attrrel;
Relation attridescs[Num_pg_attr_indices];
HeapTuple atttup; HeapTuple atttup;
Form_pg_attribute attStruct; Form_pg_attribute attStruct;
Oid attrdefOid; Oid attrdefOid;
...@@ -1235,10 +1200,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin) ...@@ -1235,10 +1200,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
tuple = heap_formtuple(adrel->rd_att, values, nulls); tuple = heap_formtuple(adrel->rd_att, values, nulls);
attrdefOid = simple_heap_insert(adrel, tuple); attrdefOid = simple_heap_insert(adrel, tuple);
CatalogOpenIndices(Num_pg_attrdef_indices, Name_pg_attrdef_indices, CatalogUpdateIndexes(adrel, tuple);
idescs);
CatalogIndexInsert(idescs, Num_pg_attrdef_indices, adrel, tuple);
CatalogCloseIndices(Num_pg_attrdef_indices, idescs);
defobject.classId = RelationGetRelid(adrel); defobject.classId = RelationGetRelid(adrel);
defobject.objectId = attrdefOid; defobject.objectId = attrdefOid;
...@@ -1269,11 +1231,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin) ...@@ -1269,11 +1231,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
{ {
attStruct->atthasdef = true; attStruct->atthasdef = true;
simple_heap_update(attrrel, &atttup->t_self, atttup); simple_heap_update(attrrel, &atttup->t_self, atttup);
/* keep catalog indices current */ /* keep catalog indexes current */
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, CatalogUpdateIndexes(attrrel, atttup);
attridescs);
CatalogIndexInsert(attridescs, Num_pg_attr_indices, attrrel, atttup);
CatalogCloseIndices(Num_pg_attr_indices, attridescs);
} }
heap_close(attrrel, RowExclusiveLock); heap_close(attrrel, RowExclusiveLock);
heap_freetuple(atttup); heap_freetuple(atttup);
...@@ -1655,7 +1614,6 @@ SetRelationNumChecks(Relation rel, int numchecks) ...@@ -1655,7 +1614,6 @@ SetRelationNumChecks(Relation rel, int numchecks)
Relation relrel; Relation relrel;
HeapTuple reltup; HeapTuple reltup;
Form_pg_class relStruct; Form_pg_class relStruct;
Relation relidescs[Num_pg_class_indices];
relrel = heap_openr(RelationRelationName, RowExclusiveLock); relrel = heap_openr(RelationRelationName, RowExclusiveLock);
reltup = SearchSysCacheCopy(RELOID, reltup = SearchSysCacheCopy(RELOID,
...@@ -1672,11 +1630,8 @@ SetRelationNumChecks(Relation rel, int numchecks) ...@@ -1672,11 +1630,8 @@ SetRelationNumChecks(Relation rel, int numchecks)
simple_heap_update(relrel, &reltup->t_self, reltup); simple_heap_update(relrel, &reltup->t_self, reltup);
/* keep catalog indices current */ /* keep catalog indexes current */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, CatalogUpdateIndexes(relrel, reltup);
relidescs);
CatalogIndexInsert(relidescs, Num_pg_class_indices, relrel, reltup);
CatalogCloseIndices(Num_pg_class_indices, relidescs);
} }
else else
{ {
...@@ -1866,9 +1821,9 @@ RemoveStatistics(Relation rel) ...@@ -1866,9 +1821,9 @@ RemoveStatistics(Relation rel)
/* /*
* RelationTruncateIndexes - truncate all * 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. * the relation specified by the heapId parameter.
*/ */
static void static void
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * INTERFACE ROUTINES
...@@ -314,7 +314,6 @@ UpdateRelationRelation(Relation indexRelation) ...@@ -314,7 +314,6 @@ UpdateRelationRelation(Relation indexRelation)
{ {
Relation pg_class; Relation pg_class;
HeapTuple tuple; HeapTuple tuple;
Relation idescs[Num_pg_class_indices];
pg_class = heap_openr(RelationRelationName, RowExclusiveLock); pg_class = heap_openr(RelationRelationName, RowExclusiveLock);
...@@ -332,18 +331,8 @@ UpdateRelationRelation(Relation indexRelation) ...@@ -332,18 +331,8 @@ UpdateRelationRelation(Relation indexRelation)
HeapTupleSetOid(tuple, RelationGetRelid(indexRelation)); HeapTupleSetOid(tuple, RelationGetRelid(indexRelation));
simple_heap_insert(pg_class, tuple); simple_heap_insert(pg_class, tuple);
/* /* update the system catalog indexes */
* During normal processing, we need to make sure that the system CatalogUpdateIndexes(pg_class, tuple);
* 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);
}
heap_freetuple(tuple); heap_freetuple(tuple);
heap_close(pg_class, RowExclusiveLock); heap_close(pg_class, RowExclusiveLock);
...@@ -375,23 +364,17 @@ static void ...@@ -375,23 +364,17 @@ static void
AppendAttributeTuples(Relation indexRelation, int numatts) AppendAttributeTuples(Relation indexRelation, int numatts)
{ {
Relation pg_attribute; Relation pg_attribute;
bool hasind; CatalogIndexState indstate;
Relation idescs[Num_pg_attr_indices];
TupleDesc indexTupDesc; TupleDesc indexTupDesc;
HeapTuple new_tuple; HeapTuple new_tuple;
int i; int i;
/* /*
* open the attribute relation * open the attribute relation and its indexes
*/ */
pg_attribute = heap_openr(AttributeRelationName, RowExclusiveLock); pg_attribute = heap_openr(AttributeRelationName, RowExclusiveLock);
hasind = false; indstate = CatalogOpenIndexes(pg_attribute);
if (!IsIgnoringSystemIndexes() && pg_attribute->rd_rel->relhasindex)
{
hasind = true;
CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
}
/* /*
* insert data from new index's tupdesc into pg_attribute * insert data from new index's tupdesc into pg_attribute
...@@ -414,14 +397,12 @@ AppendAttributeTuples(Relation indexRelation, int numatts) ...@@ -414,14 +397,12 @@ AppendAttributeTuples(Relation indexRelation, int numatts)
simple_heap_insert(pg_attribute, new_tuple); simple_heap_insert(pg_attribute, new_tuple);
if (hasind) CatalogIndexInsert(indstate, new_tuple);
CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, new_tuple);
heap_freetuple(new_tuple); heap_freetuple(new_tuple);
} }
if (hasind) CatalogCloseIndexes(indstate);
CatalogCloseIndices(Num_pg_attr_indices, idescs);
heap_close(pg_attribute, RowExclusiveLock); heap_close(pg_attribute, RowExclusiveLock);
} }
...@@ -445,7 +426,6 @@ UpdateIndexRelation(Oid indexoid, ...@@ -445,7 +426,6 @@ UpdateIndexRelation(Oid indexoid,
Relation pg_index; Relation pg_index;
HeapTuple tuple; HeapTuple tuple;
int i; int i;
Relation idescs[Num_pg_index_indices];
/* /*
* allocate a Form_pg_index big enough to hold the index-predicate (if * allocate a Form_pg_index big enough to hold the index-predicate (if
...@@ -503,19 +483,12 @@ UpdateIndexRelation(Oid indexoid, ...@@ -503,19 +483,12 @@ UpdateIndexRelation(Oid indexoid,
(void *) indexForm); (void *) indexForm);
/* /*
* insert the tuple into the pg_index * insert the tuple into the pg_index catalog
*/ */
simple_heap_insert(pg_index, tuple); simple_heap_insert(pg_index, tuple);
/* /* update the indexes on pg_index */
* add index tuples for it CatalogUpdateIndexes(pg_index, tuple);
*/
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);
}
/* /*
* close the relation and free the tuple * close the relation and free the tuple
...@@ -774,7 +747,7 @@ index_create(Oid heapRelationId, ...@@ -774,7 +747,7 @@ index_create(Oid heapRelationId,
/* /*
* If this is bootstrap (initdb) time, then we don't actually fill in * 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 * so we delay filling them in until just before we're done with
* bootstrapping. Otherwise, we call the routine that constructs the * bootstrapping. Otherwise, we call the routine that constructs the
* index. * index.
...@@ -1245,16 +1218,8 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid) ...@@ -1245,16 +1218,8 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid)
{ {
simple_heap_update(pg_class, &tuple->t_self, tuple); simple_heap_update(pg_class, &tuple->t_self, tuple);
/* Keep the catalog indices up to date */ /* Keep the catalog indexes up to date */
if (!IsIgnoringSystemIndexes()) CatalogUpdateIndexes(pg_class, tuple);
{
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);
}
} }
else else
{ {
...@@ -1273,8 +1238,7 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid) ...@@ -1273,8 +1238,7 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid)
void void
setNewRelfilenode(Relation relation) setNewRelfilenode(Relation relation)
{ {
Relation pg_class, Relation pg_class;
idescs[Num_pg_class_indices];
Oid newrelfilenode; Oid newrelfilenode;
bool in_place_update = false; bool in_place_update = false;
HeapTupleData lockTupleData; HeapTupleData lockTupleData;
...@@ -1321,14 +1285,10 @@ setNewRelfilenode(Relation relation) ...@@ -1321,14 +1285,10 @@ setNewRelfilenode(Relation relation)
WriteBuffer(buffer); WriteBuffer(buffer);
BufferSync(); BufferSync();
} }
/* Keep the catalog indices up to date */ /* Keep the catalog indexes up to date */
if (!in_place_update && pg_class->rd_rel->relhasindex) if (!in_place_update)
{ CatalogUpdateIndexes(pg_class, classTuple);
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);
}
heap_close(pg_class, NoLock); heap_close(pg_class, NoLock);
if (!in_place_update) if (!in_place_update)
heap_freetuple(classTuple); heap_freetuple(classTuple);
...@@ -1355,7 +1315,6 @@ UpdateStats(Oid relid, double reltuples) ...@@ -1355,7 +1315,6 @@ UpdateStats(Oid relid, double reltuples)
BlockNumber relpages; BlockNumber relpages;
int i; int i;
Form_pg_class rd_rel; Form_pg_class rd_rel;
Relation idescs[Num_pg_class_indices];
Datum values[Natts_pg_class]; Datum values[Natts_pg_class];
char nulls[Natts_pg_class]; char nulls[Natts_pg_class];
char replace[Natts_pg_class]; char replace[Natts_pg_class];
...@@ -1494,12 +1453,7 @@ UpdateStats(Oid relid, double reltuples) ...@@ -1494,12 +1453,7 @@ UpdateStats(Oid relid, double reltuples)
values[Anum_pg_class_reltuples - 1] = Float4GetDatum((float4) reltuples); values[Anum_pg_class_reltuples - 1] = Float4GetDatum((float4) reltuples);
newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace); newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace);
simple_heap_update(pg_class, &tuple->t_self, newtup); simple_heap_update(pg_class, &tuple->t_self, newtup);
if (!IsIgnoringSystemIndexes()) CatalogUpdateIndexes(pg_class, newtup);
{
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);
}
heap_freetuple(newtup); heap_freetuple(newtup);
} }
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* indexing.c * indexing.c
* This file contains routines to support indices defined on system * This file contains routines to support indexes defined on system
* catalogs. * catalogs.
* *
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
...@@ -9,155 +9,103 @@ ...@@ -9,155 +9,103 @@
* *
* *
* IDENTIFICATION * 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 "postgres.h"
#include "access/genam.h" #include "access/genam.h"
#include "access/heapam.h"
#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/index.h" #include "catalog/index.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/pg_index.h" #include "executor/executor.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};
/* /*
* Changes (appends) to catalogs can and do happen at various places * CatalogOpenIndexes - open the indexes on a system catalog.
* 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 * When inserting or updating tuples in a system catalog, call this
* associated with them. * 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 CatalogIndexState
CatalogOpenIndices(int nIndices, char **names, Relation *idescs) CatalogOpenIndexes(Relation heapRel)
{ {
int i; ResultRelInfo *resultRelInfo;
resultRelInfo = makeNode(ResultRelInfo);
resultRelInfo->ri_RangeTableIndex = 1; /* dummy */
resultRelInfo->ri_RelationDesc = heapRel;
resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
ExecOpenIndices(resultRelInfo);
if (IsIgnoringSystemIndexes()) return resultRelInfo;
return;
for (i = 0; i < nIndices; i++)
idescs[i] = index_openr(names[i]);
} }
/* /*
* This is the inverse routine to CatalogOpenIndices() * CatalogCloseIndexes - clean up resources allocated by CatalogOpenIndexes
*/ */
void void
CatalogCloseIndices(int nIndices, Relation *idescs) CatalogCloseIndexes(CatalogIndexState indstate)
{ {
int i; ExecCloseIndices(indstate);
pfree(indstate);
if (IsIgnoringSystemIndexes())
return;
for (i = 0; i < nIndices; i++)
index_close(idescs[i]);
} }
/* /*
* For the same reasons outlined above for CatalogOpenIndices(), we need a * CatalogIndexInsert - insert index entries for one catalog tuple
* routine that takes a new catalog tuple and inserts an associated index
* tuple into each catalog index.
* *
* NOTE: since this routine looks up all the pg_index data on each call, * This should be called for each inserted or updated catalog tuple.
* 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.
* *
* NOTE: we do not bother to handle partial indices. Nor do we try to * This is effectively a cut-down version of ExecInsertIndexTuples.
* 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!
*/ */
void void
CatalogIndexInsert(Relation *idescs, CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
int nIndices,
Relation heapRelation,
HeapTuple heapTuple)
{ {
int i;
int numIndexes;
RelationPtr relationDescs;
Relation heapRelation;
TupleDesc heapDescriptor; TupleDesc heapDescriptor;
IndexInfo **indexInfoArray;
Datum datum[INDEX_MAX_KEYS]; Datum datum[INDEX_MAX_KEYS];
char nullv[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); 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; 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, FormIndexDatum(indexInfo,
heapTuple, heapTuple,
heapDescriptor, heapDescriptor,
...@@ -165,11 +113,35 @@ CatalogIndexInsert(Relation *idescs, ...@@ -165,11 +113,35 @@ CatalogIndexInsert(Relation *idescs,
datum, datum,
nullv); nullv);
indexRes = index_insert(idescs[i], datum, nullv, /*
&heapTuple->t_self, heapRelation, * The index AM does the rest.
idescs[i]->rd_uniqueindex); */
if (indexRes) result = index_insert(relationDescs[i], /* index relation */
pfree(indexRes); datum, /* array of heaptuple Datums */
pfree(indexInfo); 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);
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -175,14 +175,7 @@ AggregateCreate(const char *aggName, ...@@ -175,14 +175,7 @@ AggregateCreate(const char *aggName,
tup = heap_formtuple(tupDesc, values, nulls); tup = heap_formtuple(tupDesc, values, nulls);
simple_heap_insert(aggdesc, tup); simple_heap_insert(aggdesc, tup);
if (RelationGetForm(aggdesc)->relhasindex) CatalogUpdateIndexes(aggdesc, tup);
{
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);
}
heap_close(aggdesc, RowExclusiveLock); heap_close(aggdesc, RowExclusiveLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -152,15 +152,8 @@ CreateConstraintEntry(const char *constraintName, ...@@ -152,15 +152,8 @@ CreateConstraintEntry(const char *constraintName,
conOid = simple_heap_insert(conDesc, tup); conOid = simple_heap_insert(conDesc, tup);
/* Handle Indices */ /* update catalog indexes */
if (RelationGetForm(conDesc)->relhasindex) CatalogUpdateIndexes(conDesc, tup);
{
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);
}
conobject.classId = RelationGetRelid(conDesc); conobject.classId = RelationGetRelid(conDesc);
conobject.objectId = conOid; conobject.objectId = conOid;
...@@ -426,7 +419,6 @@ RemoveConstraintById(Oid conId) ...@@ -426,7 +419,6 @@ RemoveConstraintById(Oid conId)
Relation pgrel; Relation pgrel;
HeapTuple relTup; HeapTuple relTup;
Form_pg_class classForm; Form_pg_class classForm;
Relation ridescs[Num_pg_class_indices];
pgrel = heap_openr(RelationRelationName, RowExclusiveLock); pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
relTup = SearchSysCacheCopy(RELOID, relTup = SearchSysCacheCopy(RELOID,
...@@ -444,9 +436,7 @@ RemoveConstraintById(Oid conId) ...@@ -444,9 +436,7 @@ RemoveConstraintById(Oid conId)
simple_heap_update(pgrel, &relTup->t_self, relTup); simple_heap_update(pgrel, &relTup->t_self, relTup);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs); CatalogUpdateIndexes(pgrel, relTup);
CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, relTup);
CatalogCloseIndices(Num_pg_class_indices, ridescs);
heap_freetuple(relTup); heap_freetuple(relTup);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -105,14 +105,7 @@ Oid ConversionCreate(const char *conname, Oid connamespace, ...@@ -105,14 +105,7 @@ Oid ConversionCreate(const char *conname, Oid connamespace,
Assert(OidIsValid(oid)); Assert(OidIsValid(oid));
/* update the index if any */ /* update the index if any */
if (RelationGetForm(rel)->relhasindex) CatalogUpdateIndexes(rel, tup);
{
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);
}
myself.classId = get_system_catalog_relid(ConversionRelationName); myself.classId = get_system_catalog_relid(ConversionRelationName);
myself.objectId = HeapTupleGetOid(tup); myself.objectId = HeapTupleGetOid(tup);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,12 +53,11 @@ recordMultipleDependencies(const ObjectAddress *depender, ...@@ -53,12 +53,11 @@ recordMultipleDependencies(const ObjectAddress *depender,
DependencyType behavior) DependencyType behavior)
{ {
Relation dependDesc; Relation dependDesc;
CatalogIndexState indstate;
HeapTuple tup; HeapTuple tup;
int i; int i;
char nulls[Natts_pg_depend]; char nulls[Natts_pg_depend];
Datum values[Natts_pg_depend]; Datum values[Natts_pg_depend];
Relation idescs[Num_pg_depend_indices];
bool indices_opened = false;
if (nreferenced <= 0) if (nreferenced <= 0)
return; /* nothing to do */ return; /* nothing to do */
...@@ -72,6 +71,9 @@ recordMultipleDependencies(const ObjectAddress *depender, ...@@ -72,6 +71,9 @@ recordMultipleDependencies(const ObjectAddress *depender,
dependDesc = heap_openr(DependRelationName, RowExclusiveLock); dependDesc = heap_openr(DependRelationName, RowExclusiveLock);
/* Don't open indexes unless we need to make an update */
indstate = NULL;
memset(nulls, ' ', sizeof(nulls)); memset(nulls, ' ', sizeof(nulls));
for (i = 0; i < nreferenced; i++, referenced++) for (i = 0; i < nreferenced; i++, referenced++)
...@@ -101,22 +103,18 @@ recordMultipleDependencies(const ObjectAddress *depender, ...@@ -101,22 +103,18 @@ recordMultipleDependencies(const ObjectAddress *depender,
simple_heap_insert(dependDesc, tup); simple_heap_insert(dependDesc, tup);
/* /* keep indexes current */
* Keep indices current if (indstate == NULL)
*/ indstate = CatalogOpenIndexes(dependDesc);
if (!indices_opened)
{ CatalogIndexInsert(indstate, tup);
CatalogOpenIndices(Num_pg_depend_indices, Name_pg_depend_indices, idescs);
indices_opened = true;
}
CatalogIndexInsert(idescs, Num_pg_depend_indices, dependDesc, tup);
heap_freetuple(tup); heap_freetuple(tup);
} }
} }
if (indices_opened) if (indstate != NULL)
CatalogCloseIndices(Num_pg_depend_indices, idescs); CatalogCloseIndexes(indstate);
heap_close(dependDesc, RowExclusiveLock); heap_close(dependDesc, RowExclusiveLock);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -36,7 +36,6 @@ LargeObjectCreate(Oid loid) ...@@ -36,7 +36,6 @@ LargeObjectCreate(Oid loid)
{ {
Relation pg_largeobject; Relation pg_largeobject;
HeapTuple ntup; HeapTuple ntup;
Relation idescs[Num_pg_largeobject_indices];
Datum values[Natts_pg_largeobject]; Datum values[Natts_pg_largeobject];
char nulls[Natts_pg_largeobject]; char nulls[Natts_pg_largeobject];
int i; int i;
...@@ -65,15 +64,8 @@ LargeObjectCreate(Oid loid) ...@@ -65,15 +64,8 @@ LargeObjectCreate(Oid loid)
*/ */
simple_heap_insert(pg_largeobject, ntup); simple_heap_insert(pg_largeobject, ntup);
/* /* Update indexes */
* Update indices CatalogUpdateIndexes(pg_largeobject, ntup);
*/
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);
}
heap_close(pg_largeobject, RowExclusiveLock); heap_close(pg_largeobject, RowExclusiveLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -63,17 +63,11 @@ NamespaceCreate(const char *nspName, int32 ownerSysId) ...@@ -63,17 +63,11 @@ NamespaceCreate(const char *nspName, int32 ownerSysId)
tupDesc = nspdesc->rd_att; tupDesc = nspdesc->rd_att;
tup = heap_formtuple(tupDesc, values, nulls); tup = heap_formtuple(tupDesc, values, nulls);
nspoid = simple_heap_insert(nspdesc, tup); nspoid = simple_heap_insert(nspdesc, tup);
Assert(OidIsValid(nspoid)); Assert(OidIsValid(nspoid));
if (RelationGetForm(nspdesc)->relhasindex) CatalogUpdateIndexes(nspdesc, tup);
{
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);
}
heap_close(nspdesc, RowExclusiveLock); heap_close(nspdesc, RowExclusiveLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* these routines moved here from commands/define.c and somewhat cleaned up. * these routines moved here from commands/define.c and somewhat cleaned up.
...@@ -263,14 +263,7 @@ OperatorShellMake(const char *operatorName, ...@@ -263,14 +263,7 @@ OperatorShellMake(const char *operatorName,
*/ */
operatorObjectId = simple_heap_insert(pg_operator_desc, tup); operatorObjectId = simple_heap_insert(pg_operator_desc, tup);
if (RelationGetForm(pg_operator_desc)->relhasindex) CatalogUpdateIndexes(pg_operator_desc, tup);
{
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);
}
/* Add dependencies for the entry */ /* Add dependencies for the entry */
makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc)); makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc));
...@@ -646,14 +639,7 @@ OperatorCreate(const char *operatorName, ...@@ -646,14 +639,7 @@ OperatorCreate(const char *operatorName,
} }
/* Must update the indexes in either case */ /* Must update the indexes in either case */
if (RelationGetForm(pg_operator_desc)->relhasindex) CatalogUpdateIndexes(pg_operator_desc, tup);
{
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);
}
/* Add dependencies for the entry */ /* Add dependencies for the entry */
makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc)); makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc));
...@@ -815,14 +801,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) ...@@ -815,14 +801,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
simple_heap_update(pg_operator_desc, &tup->t_self, tup); simple_heap_update(pg_operator_desc, &tup->t_self, tup);
if (RelationGetForm(pg_operator_desc)->relhasindex) CatalogUpdateIndexes(pg_operator_desc, tup);
{
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);
}
} }
} }
...@@ -847,14 +826,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) ...@@ -847,14 +826,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
simple_heap_update(pg_operator_desc, &tup->t_self, tup); simple_heap_update(pg_operator_desc, &tup->t_self, tup);
if (RelationGetForm(pg_operator_desc)->relhasindex) CatalogUpdateIndexes(pg_operator_desc, tup);
{
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);
}
values[Anum_pg_operator_oprcom - 1] = (Datum) NULL; values[Anum_pg_operator_oprcom - 1] = (Datum) NULL;
replaces[Anum_pg_operator_oprcom - 1] = ' '; replaces[Anum_pg_operator_oprcom - 1] = ' ';
...@@ -880,14 +852,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) ...@@ -880,14 +852,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
simple_heap_update(pg_operator_desc, &tup->t_self, tup); simple_heap_update(pg_operator_desc, &tup->t_self, tup);
if (RelationGetForm(pg_operator_desc)->relhasindex) CatalogUpdateIndexes(pg_operator_desc, tup);
{
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);
}
} }
heap_close(pg_operator_desc, RowExclusiveLock); heap_close(pg_operator_desc, RowExclusiveLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -236,15 +236,8 @@ ProcedureCreate(const char *procedureName, ...@@ -236,15 +236,8 @@ ProcedureCreate(const char *procedureName,
is_update = false; is_update = false;
} }
/* Need to update indices for either the insert or update case */ /* Need to update indexes for either the insert or update case */
if (RelationGetForm(rel)->relhasindex) CatalogUpdateIndexes(rel, tup);
{
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);
}
AssertTupleDescHasOid(tupDesc); AssertTupleDescHasOid(tupDesc);
retval = HeapTupleGetOid(tup); retval = HeapTupleGetOid(tup);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -103,14 +103,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace) ...@@ -103,14 +103,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace)
*/ */
typoid = simple_heap_insert(pg_type_desc, tup); typoid = simple_heap_insert(pg_type_desc, tup);
if (RelationGetForm(pg_type_desc)->relhasindex) CatalogUpdateIndexes(pg_type_desc, tup);
{
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);
}
/* /*
* clean up and return the type-oid * clean up and return the type-oid
...@@ -280,15 +273,8 @@ TypeCreate(const char *typeName, ...@@ -280,15 +273,8 @@ TypeCreate(const char *typeName,
typeObjectId = simple_heap_insert(pg_type_desc, tup); typeObjectId = simple_heap_insert(pg_type_desc, tup);
} }
/* Update indices (not necessary if bootstrapping) */ /* Update indexes */
if (RelationGetForm(pg_type_desc)->relhasindex) CatalogUpdateIndexes(pg_type_desc, tup);
{
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);
}
/* /*
* Create dependencies. We can/must skip this in bootstrap mode. * Create dependencies. We can/must skip this in bootstrap mode.
...@@ -382,7 +368,6 @@ TypeRename(const char *oldTypeName, Oid typeNamespace, ...@@ -382,7 +368,6 @@ TypeRename(const char *oldTypeName, Oid typeNamespace,
const char *newTypeName) const char *newTypeName)
{ {
Relation pg_type_desc; Relation pg_type_desc;
Relation idescs[Num_pg_type_indices];
HeapTuple tuple; HeapTuple tuple;
pg_type_desc = heap_openr(TypeRelationName, RowExclusiveLock); pg_type_desc = heap_openr(TypeRelationName, RowExclusiveLock);
...@@ -404,10 +389,8 @@ TypeRename(const char *oldTypeName, Oid typeNamespace, ...@@ -404,10 +389,8 @@ TypeRename(const char *oldTypeName, Oid typeNamespace,
simple_heap_update(pg_type_desc, &tuple->t_self, tuple); simple_heap_update(pg_type_desc, &tuple->t_self, tuple);
/* update the system catalog indices */ /* update the system catalog indexes */
CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs); CatalogUpdateIndexes(pg_type_desc, tuple);
CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tuple);
CatalogCloseIndices(Num_pg_type_indices, idescs);
heap_freetuple(tuple); heap_freetuple(tuple);
heap_close(pg_type_desc, RowExclusiveLock); heap_close(pg_type_desc, RowExclusiveLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1670,7 +1670,6 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats) ...@@ -1670,7 +1670,6 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
Datum values[Natts_pg_statistic]; Datum values[Natts_pg_statistic];
char nulls[Natts_pg_statistic]; char nulls[Natts_pg_statistic];
char replaces[Natts_pg_statistic]; char replaces[Natts_pg_statistic];
Relation irelations[Num_pg_statistic_indices];
/* Ignore attr if we weren't able to collect stats */ /* Ignore attr if we weren't able to collect stats */
if (!stats->stats_valid) if (!stats->stats_valid)
...@@ -1784,11 +1783,8 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats) ...@@ -1784,11 +1783,8 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
simple_heap_insert(sd, stup); simple_heap_insert(sd, stup);
} }
/* update indices too */ /* update indexes too */
CatalogOpenIndices(Num_pg_statistic_indices, Name_pg_statistic_indices, CatalogUpdateIndexes(sd, stup);
irelations);
CatalogIndexInsert(irelations, Num_pg_statistic_indices, sd, stup);
CatalogCloseIndices(Num_pg_statistic_indices, irelations);
heap_freetuple(stup); heap_freetuple(stup);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -245,14 +245,7 @@ Async_Listen(char *relname, int pid) ...@@ -245,14 +245,7 @@ Async_Listen(char *relname, int pid)
simple_heap_insert(lRel, tuple); simple_heap_insert(lRel, tuple);
#ifdef NOT_USED /* currently there are no indexes */ #ifdef NOT_USED /* currently there are no indexes */
if (RelationGetForm(lRel)->relhasindex) CatalogUpdateIndexes(lRel, tuple);
{
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);
}
#endif #endif
heap_freetuple(tuple); heap_freetuple(tuple);
...@@ -529,14 +522,7 @@ AtCommit_Notify(void) ...@@ -529,14 +522,7 @@ AtCommit_Notify(void)
simple_heap_update(lRel, &lTuple->t_self, rTuple); simple_heap_update(lRel, &lTuple->t_self, rTuple);
#ifdef NOT_USED /* currently there are no indexes */ #ifdef NOT_USED /* currently there are no indexes */
if (RelationGetForm(lRel)->relhasindex) CatalogUpdateIndexes(lRel, rTuple);
{
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);
}
#endif #endif
} }
} }
...@@ -802,14 +788,7 @@ ProcessIncomingNotify(void) ...@@ -802,14 +788,7 @@ ProcessIncomingNotify(void)
simple_heap_update(lRel, &lTuple->t_self, rTuple); simple_heap_update(lRel, &lTuple->t_self, rTuple);
#ifdef NOT_USED /* currently there are no indexes */ #ifdef NOT_USED /* currently there are no indexes */
if (RelationGetForm(lRel)->relhasindex) CatalogUpdateIndexes(lRel, rTuple);
{
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);
}
#endif #endif
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1996-2001, PostgreSQL Global Development Group * Copyright (c) 1996-2001, PostgreSQL Global Development Group
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -206,19 +206,9 @@ CreateComments(Oid oid, Oid classoid, int32 subid, char *comment) ...@@ -206,19 +206,9 @@ CreateComments(Oid oid, Oid classoid, int32 subid, char *comment)
} }
/* Update indexes, if necessary */ /* Update indexes, if necessary */
if (newtuple != NULL) if (newtuple != NULL)
{ {
if (RelationGetForm(description)->relhasindex) CatalogUpdateIndexes(description, newtuple);
{
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);
}
heap_freetuple(newtuple); heap_freetuple(newtuple);
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -347,19 +347,8 @@ createdb(const CreatedbStmt *stmt) ...@@ -347,19 +347,8 @@ createdb(const CreatedbStmt *stmt)
simple_heap_insert(pg_database_rel, tuple); simple_heap_insert(pg_database_rel, tuple);
/* /* Update indexes */
* Update indexes CatalogUpdateIndexes(pg_database_rel, tuple);
*/
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);
}
/* Close pg_database, but keep lock till commit */ /* Close pg_database, but keep lock till commit */
heap_close(pg_database_rel, NoLock); heap_close(pg_database_rel, NoLock);
...@@ -562,19 +551,8 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt) ...@@ -562,19 +551,8 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
newtuple = heap_modifytuple(tuple, rel, repl_val, repl_null, repl_repl); newtuple = heap_modifytuple(tuple, rel, repl_val, repl_null, repl_repl);
simple_heap_update(rel, &tuple->t_self, newtuple); simple_heap_update(rel, &tuple->t_self, newtuple);
/* /* Update indexes */
* Update indexes CatalogUpdateIndexes(rel, newtuple);
*/
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);
}
heap_endscan(scan); heap_endscan(scan);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 * DESCRIPTION
* These routines take the parse tree and pick out the * These routines take the parse tree and pick out the
...@@ -685,16 +685,10 @@ CreateCast(CreateCastStmt *stmt) ...@@ -685,16 +685,10 @@ CreateCast(CreateCastStmt *stmt)
nulls[i] = ' '; nulls[i] = ' ';
tuple = heap_formtuple(RelationGetDescr(relation), values, nulls); tuple = heap_formtuple(RelationGetDescr(relation), values, nulls);
simple_heap_insert(relation, tuple);
if (RelationGetForm(relation)->relhasindex) simple_heap_insert(relation, tuple);
{
Relation idescs[Num_pg_cast_indices];
CatalogOpenIndices(Num_pg_cast_indices, Name_pg_cast_indices, idescs); CatalogUpdateIndexes(relation, tuple);
CatalogIndexInsert(idescs, Num_pg_cast_indices, relation, tuple);
CatalogCloseIndices(Num_pg_cast_indices, idescs);
}
myself.classId = RelationGetRelid(relation); myself.classId = RelationGetRelid(relation);
myself.objectId = HeapTupleGetOid(tuple); myself.objectId = HeapTupleGetOid(tuple);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -286,15 +286,7 @@ DefineOpClass(CreateOpClassStmt *stmt) ...@@ -286,15 +286,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
opclassoid = simple_heap_insert(rel, tup); opclassoid = simple_heap_insert(rel, tup);
if (RelationGetForm(rel)->relhasindex) CatalogUpdateIndexes(rel, tup);
{
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);
}
heap_freetuple(tup); heap_freetuple(tup);
...@@ -395,15 +387,8 @@ storeOperators(Oid opclassoid, int numOperators, ...@@ -395,15 +387,8 @@ storeOperators(Oid opclassoid, int numOperators,
simple_heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (RelationGetForm(rel)->relhasindex) CatalogUpdateIndexes(rel, tup);
{
Relation idescs[Num_pg_amop_indices];
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); heap_freetuple(tup);
} }
...@@ -444,15 +429,8 @@ storeProcedures(Oid opclassoid, int numProcs, Oid *procedures) ...@@ -444,15 +429,8 @@ storeProcedures(Oid opclassoid, int numProcs, Oid *procedures)
simple_heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (RelationGetForm(rel)->relhasindex) CatalogUpdateIndexes(rel, tup);
{
Relation idescs[Num_pg_amproc_indices];
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); heap_freetuple(tup);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -119,14 +119,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt) ...@@ -119,14 +119,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
simple_heap_insert(rel, tup); simple_heap_insert(rel, tup);
if (RelationGetForm(rel)->relhasindex) CatalogUpdateIndexes(rel, tup);
{
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);
}
/* /*
* Create dependencies for language * Create dependencies for language
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -325,7 +325,7 @@ RemoveRelation(const RangeVar *relation, DropBehavior behavior) ...@@ -325,7 +325,7 @@ RemoveRelation(const RangeVar *relation, DropBehavior behavior)
* BadArg if name is invalid * BadArg if name is invalid
* *
* Note: * Note:
* Rows are removed, indices are truncated and reconstructed. * Rows are removed, indexes are truncated and reconstructed.
*/ */
void void
TruncateRelation(const RangeVar *relation) TruncateRelation(const RangeVar *relation)
...@@ -832,14 +832,7 @@ StoreCatalogInheritance(Oid relationId, List *supers) ...@@ -832,14 +832,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
simple_heap_insert(relation, tuple); simple_heap_insert(relation, tuple);
if (RelationGetForm(relation)->relhasindex) CatalogUpdateIndexes(relation, tuple);
{
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);
}
heap_freetuple(tuple); heap_freetuple(tuple);
...@@ -969,7 +962,6 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass) ...@@ -969,7 +962,6 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
{ {
Relation relationRelation; Relation relationRelation;
HeapTuple tuple; HeapTuple tuple;
Relation idescs[Num_pg_class_indices];
/* /*
* Fetch a modifiable copy of the tuple, modify it, update pg_class. * Fetch a modifiable copy of the tuple, modify it, update pg_class.
...@@ -984,10 +976,8 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass) ...@@ -984,10 +976,8 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
((Form_pg_class) GETSTRUCT(tuple))->relhassubclass = relhassubclass; ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass = relhassubclass;
simple_heap_update(relationRelation, &tuple->t_self, tuple); simple_heap_update(relationRelation, &tuple->t_self, tuple);
/* keep the catalog indices up to date */ /* keep the catalog indexes up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); CatalogUpdateIndexes(relationRelation, tuple);
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
CatalogCloseIndices(Num_pg_class_indices, idescs);
heap_freetuple(tuple); heap_freetuple(tuple);
heap_close(relationRelation, RowExclusiveLock); heap_close(relationRelation, RowExclusiveLock);
...@@ -1097,14 +1087,8 @@ renameatt(Oid relid, ...@@ -1097,14 +1087,8 @@ renameatt(Oid relid,
simple_heap_update(attrelation, &atttup->t_self, atttup); simple_heap_update(attrelation, &atttup->t_self, atttup);
/* keep system catalog indices current */ /* keep system catalog indexes current */
{ CatalogUpdateIndexes(attrelation, atttup);
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);
}
heap_freetuple(atttup); heap_freetuple(atttup);
...@@ -1151,14 +1135,9 @@ renameatt(Oid relid, ...@@ -1151,14 +1135,9 @@ renameatt(Oid relid,
simple_heap_update(attrelation, &atttup->t_self, atttup); simple_heap_update(attrelation, &atttup->t_self, atttup);
/* keep system catalog indices current */ /* keep system catalog indexes current */
{ CatalogUpdateIndexes(attrelation, atttup);
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);
}
heap_freetuple(atttup); heap_freetuple(atttup);
} }
...@@ -1203,7 +1182,6 @@ renamerel(Oid relid, const char *newrelname) ...@@ -1203,7 +1182,6 @@ renamerel(Oid relid, const char *newrelname)
char *oldrelname; char *oldrelname;
char relkind; char relkind;
bool relhastriggers; bool relhastriggers;
Relation irelations[Num_pg_class_indices];
/* /*
* Grab an exclusive lock on the target table or index, which we will * Grab an exclusive lock on the target table or index, which we will
...@@ -1247,10 +1225,8 @@ renamerel(Oid relid, const char *newrelname) ...@@ -1247,10 +1225,8 @@ renamerel(Oid relid, const char *newrelname)
simple_heap_update(relrelation, &reltup->t_self, reltup); simple_heap_update(relrelation, &reltup->t_self, reltup);
/* keep the system catalog indices current */ /* keep the system catalog indexes current */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, irelations); CatalogUpdateIndexes(relrelation, reltup);
CatalogIndexInsert(irelations, Num_pg_class_indices, relrelation, reltup);
CatalogCloseIndices(Num_pg_class_indices, irelations);
heap_close(relrelation, NoLock); heap_close(relrelation, NoLock);
heap_freetuple(reltup); heap_freetuple(reltup);
...@@ -1481,13 +1457,7 @@ update_ri_trigger_args(Oid relid, ...@@ -1481,13 +1457,7 @@ update_ri_trigger_args(Oid relid,
*/ */
simple_heap_update(tgrel, &tuple->t_self, tuple); simple_heap_update(tgrel, &tuple->t_self, tuple);
{ CatalogUpdateIndexes(tgrel, 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);
}
/* free up our scratch memory */ /* free up our scratch memory */
pfree(newtgargs); pfree(newtgargs);
...@@ -1703,14 +1673,7 @@ AlterTableAddColumn(Oid myrelid, ...@@ -1703,14 +1673,7 @@ AlterTableAddColumn(Oid myrelid,
simple_heap_insert(attrdesc, attributeTuple); simple_heap_insert(attrdesc, attributeTuple);
/* Update indexes on pg_attribute */ /* Update indexes on pg_attribute */
if (RelationGetForm(attrdesc)->relhasindex) CatalogUpdateIndexes(attrdesc, attributeTuple);
{
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);
}
heap_close(attrdesc, RowExclusiveLock); heap_close(attrdesc, RowExclusiveLock);
...@@ -1723,15 +1686,8 @@ AlterTableAddColumn(Oid myrelid, ...@@ -1723,15 +1686,8 @@ AlterTableAddColumn(Oid myrelid,
AssertTupleDescHasOid(pgclass->rd_att); AssertTupleDescHasOid(pgclass->rd_att);
simple_heap_update(pgclass, &newreltup->t_self, newreltup); simple_heap_update(pgclass, &newreltup->t_self, newreltup);
/* keep catalog indices current */ /* keep catalog indexes current */
if (RelationGetForm(pgclass)->relhasindex) CatalogUpdateIndexes(pgclass, newreltup);
{
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);
}
heap_freetuple(newreltup); heap_freetuple(newreltup);
ReleaseSysCache(reltup); ReleaseSysCache(reltup);
...@@ -1850,7 +1806,7 @@ AlterTableAlterColumnDropNotNull(Oid myrelid, ...@@ -1850,7 +1806,7 @@ AlterTableAlterColumnDropNotNull(Oid myrelid,
* Check that the attribute is not in a primary key * 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); indexoidlist = RelationGetIndexList(rel);
foreach(indexoidscan, indexoidlist) foreach(indexoidscan, indexoidlist)
...@@ -1902,15 +1858,8 @@ AlterTableAlterColumnDropNotNull(Oid myrelid, ...@@ -1902,15 +1858,8 @@ AlterTableAlterColumnDropNotNull(Oid myrelid,
simple_heap_update(attr_rel, &tuple->t_self, tuple); simple_heap_update(attr_rel, &tuple->t_self, tuple);
/* keep the system catalog indices current */ /* keep the system catalog indexes current */
if (RelationGetForm(attr_rel)->relhasindex) CatalogUpdateIndexes(attr_rel, tuple);
{
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);
}
heap_close(attr_rel, RowExclusiveLock); heap_close(attr_rel, RowExclusiveLock);
...@@ -2023,15 +1972,8 @@ AlterTableAlterColumnSetNotNull(Oid myrelid, ...@@ -2023,15 +1972,8 @@ AlterTableAlterColumnSetNotNull(Oid myrelid,
simple_heap_update(attr_rel, &tuple->t_self, tuple); simple_heap_update(attr_rel, &tuple->t_self, tuple);
/* keep the system catalog indices current */ /* keep the system catalog indexes current */
if (RelationGetForm(attr_rel)->relhasindex) CatalogUpdateIndexes(attr_rel, tuple);
{
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);
}
heap_close(attr_rel, RowExclusiveLock); heap_close(attr_rel, RowExclusiveLock);
...@@ -2278,16 +2220,11 @@ AlterTableAlterColumnFlags(Oid myrelid, ...@@ -2278,16 +2220,11 @@ AlterTableAlterColumnFlags(Oid myrelid,
simple_heap_update(attrelation, &tuple->t_self, tuple); simple_heap_update(attrelation, &tuple->t_self, tuple);
/* keep system catalog indices current */ /* keep system catalog indexes current */
{ CatalogUpdateIndexes(attrelation, tuple);
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);
}
heap_freetuple(tuple); heap_freetuple(tuple);
heap_close(attrelation, NoLock); heap_close(attrelation, NoLock);
heap_close(rel, NoLock); /* close rel, but keep lock! */ heap_close(rel, NoLock); /* close rel, but keep lock! */
} }
...@@ -3200,7 +3137,6 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId) ...@@ -3200,7 +3137,6 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId)
Relation target_rel; Relation target_rel;
Relation class_rel; Relation class_rel;
HeapTuple tuple; HeapTuple tuple;
Relation idescs[Num_pg_class_indices];
Form_pg_class tuple_class; Form_pg_class tuple_class;
/* Get exclusive lock till end of transaction on the target table */ /* Get exclusive lock till end of transaction on the target table */
...@@ -3227,10 +3163,8 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId) ...@@ -3227,10 +3163,8 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId)
tuple_class->relowner = newOwnerSysId; tuple_class->relowner = newOwnerSysId;
simple_heap_update(class_rel, &tuple->t_self, tuple); simple_heap_update(class_rel, &tuple->t_self, tuple);
/* Keep the catalog indices up to date */ /* Keep the catalog indexes up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); CatalogUpdateIndexes(class_rel, tuple);
CatalogIndexInsert(idescs, Num_pg_class_indices, class_rel, tuple);
CatalogCloseIndices(Num_pg_class_indices, idescs);
/* /*
* If we are operating on a table, also change the ownership of any * If we are operating on a table, also change the ownership of any
...@@ -3299,7 +3233,6 @@ AlterTableCreateToastTable(Oid relOid, bool silent) ...@@ -3299,7 +3233,6 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
bool shared_relation; bool shared_relation;
Relation class_rel; Relation class_rel;
Buffer buffer; Buffer buffer;
Relation ridescs[Num_pg_class_indices];
Oid toast_relid; Oid toast_relid;
Oid toast_idxid; Oid toast_idxid;
char toast_relname[NAMEDATALEN]; char toast_relname[NAMEDATALEN];
...@@ -3481,14 +3414,11 @@ AlterTableCreateToastTable(Oid relOid, bool silent) ...@@ -3481,14 +3414,11 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
* Store the toast table's OID in the parent relation's tuple * Store the toast table's OID in the parent relation's tuple
*/ */
((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid = toast_relid; ((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid = toast_relid;
simple_heap_update(class_rel, &reltup->t_self, reltup); simple_heap_update(class_rel, &reltup->t_self, reltup);
/* /* Keep catalog indexes current */
* Keep catalog indices current CatalogUpdateIndexes(class_rel, reltup);
*/
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);
heap_freetuple(reltup); heap_freetuple(reltup);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,8 +72,6 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) ...@@ -72,8 +72,6 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
ScanKeyData key; ScanKeyData key;
Relation pgrel; Relation pgrel;
HeapTuple tuple; HeapTuple tuple;
Relation idescs[Num_pg_trigger_indices];
Relation ridescs[Num_pg_class_indices];
Oid fargtypes[FUNC_MAX_ARGS]; Oid fargtypes[FUNC_MAX_ARGS];
Oid funcoid; Oid funcoid;
Oid funclang; Oid funclang;
...@@ -302,9 +300,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) ...@@ -302,9 +300,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
*/ */
simple_heap_insert(tgrel, tuple); simple_heap_insert(tgrel, tuple);
CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs); CatalogUpdateIndexes(tgrel, tuple);
CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);
CatalogCloseIndices(Num_pg_trigger_indices, idescs);
myself.classId = RelationGetRelid(tgrel); myself.classId = RelationGetRelid(tgrel);
myself.objectId = trigoid; myself.objectId = trigoid;
...@@ -333,9 +329,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) ...@@ -333,9 +329,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
simple_heap_update(pgrel, &tuple->t_self, tuple); simple_heap_update(pgrel, &tuple->t_self, tuple);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs); CatalogUpdateIndexes(pgrel, tuple);
CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
CatalogCloseIndices(Num_pg_class_indices, ridescs);
heap_freetuple(tuple); heap_freetuple(tuple);
heap_close(pgrel, RowExclusiveLock); heap_close(pgrel, RowExclusiveLock);
...@@ -447,7 +441,6 @@ RemoveTriggerById(Oid trigOid) ...@@ -447,7 +441,6 @@ RemoveTriggerById(Oid trigOid)
Relation pgrel; Relation pgrel;
HeapTuple tuple; HeapTuple tuple;
Form_pg_class classForm; Form_pg_class classForm;
Relation ridescs[Num_pg_class_indices];
tgrel = heap_openr(TriggerRelationName, RowExclusiveLock); tgrel = heap_openr(TriggerRelationName, RowExclusiveLock);
...@@ -514,9 +507,7 @@ RemoveTriggerById(Oid trigOid) ...@@ -514,9 +507,7 @@ RemoveTriggerById(Oid trigOid)
simple_heap_update(pgrel, &tuple->t_self, tuple); simple_heap_update(pgrel, &tuple->t_self, tuple);
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs); CatalogUpdateIndexes(pgrel, tuple);
CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
CatalogCloseIndices(Num_pg_class_indices, ridescs);
heap_freetuple(tuple); heap_freetuple(tuple);
...@@ -549,7 +540,6 @@ renametrig(Oid relid, ...@@ -549,7 +540,6 @@ renametrig(Oid relid,
HeapTuple tuple; HeapTuple tuple;
SysScanDesc tgscan; SysScanDesc tgscan;
ScanKeyData key[2]; ScanKeyData key[2];
Relation idescs[Num_pg_trigger_indices];
/* /*
* Grab an exclusive lock on the target table, which we will NOT * Grab an exclusive lock on the target table, which we will NOT
...@@ -610,12 +600,8 @@ renametrig(Oid relid, ...@@ -610,12 +600,8 @@ renametrig(Oid relid,
simple_heap_update(tgrel, &tuple->t_self, tuple); simple_heap_update(tgrel, &tuple->t_self, tuple);
/* /* keep system catalog indexes current */
* keep system catalog indices current CatalogUpdateIndexes(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);
/* /*
* Invalidate relation's relcache entry so that other backends (and * Invalidate relation's relcache entry so that other backends (and
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -597,19 +597,8 @@ CreateUser(CreateUserStmt *stmt) ...@@ -597,19 +597,8 @@ CreateUser(CreateUserStmt *stmt)
*/ */
simple_heap_insert(pg_shadow_rel, tuple); simple_heap_insert(pg_shadow_rel, tuple);
/* /* Update indexes */
* Update indexes CatalogUpdateIndexes(pg_shadow_rel, tuple);
*/
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);
}
/* /*
* Add the user to the groups specified. We'll just call the below * Add the user to the groups specified. We'll just call the below
...@@ -809,16 +798,7 @@ AlterUser(AlterUserStmt *stmt) ...@@ -809,16 +798,7 @@ AlterUser(AlterUserStmt *stmt)
simple_heap_update(pg_shadow_rel, &tuple->t_self, new_tuple); simple_heap_update(pg_shadow_rel, &tuple->t_self, new_tuple);
/* Update indexes */ /* Update indexes */
if (RelationGetForm(pg_shadow_rel)->relhasindex) CatalogUpdateIndexes(pg_shadow_rel, new_tuple);
{
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);
}
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
heap_freetuple(new_tuple); heap_freetuple(new_tuple);
...@@ -898,13 +878,7 @@ AlterUserSet(AlterUserSetStmt *stmt) ...@@ -898,13 +878,7 @@ AlterUserSet(AlterUserSetStmt *stmt)
newtuple = heap_modifytuple(oldtuple, rel, repl_val, repl_null, repl_repl); newtuple = heap_modifytuple(oldtuple, rel, repl_val, repl_null, repl_repl);
simple_heap_update(rel, &oldtuple->t_self, newtuple); simple_heap_update(rel, &oldtuple->t_self, newtuple);
{ CatalogUpdateIndexes(rel, 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);
}
ReleaseSysCache(oldtuple); ReleaseSysCache(oldtuple);
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
...@@ -1216,19 +1190,8 @@ CreateGroup(CreateGroupStmt *stmt) ...@@ -1216,19 +1190,8 @@ CreateGroup(CreateGroupStmt *stmt)
*/ */
simple_heap_insert(pg_group_rel, tuple); simple_heap_insert(pg_group_rel, tuple);
/* /* Update indexes */
* Update indexes CatalogUpdateIndexes(pg_group_rel, tuple);
*/
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);
}
heap_close(pg_group_rel, NoLock); heap_close(pg_group_rel, NoLock);
...@@ -1417,16 +1380,7 @@ UpdateGroupMembership(Relation group_rel, HeapTuple group_tuple, ...@@ -1417,16 +1380,7 @@ UpdateGroupMembership(Relation group_rel, HeapTuple group_tuple,
simple_heap_update(group_rel, &group_tuple->t_self, tuple); simple_heap_update(group_rel, &group_tuple->t_self, tuple);
/* Update indexes */ /* Update indexes */
if (RelationGetForm(group_rel)->relhasindex) CatalogUpdateIndexes(group_rel, tuple);
{
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);
}
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -95,16 +95,7 @@ InsertRule(char *rulname, ...@@ -95,16 +95,7 @@ InsertRule(char *rulname,
rewriteObjectId = simple_heap_insert(pg_rewrite_desc, tup); rewriteObjectId = simple_heap_insert(pg_rewrite_desc, tup);
if (RelationGetForm(pg_rewrite_desc)->relhasindex) CatalogUpdateIndexes(pg_rewrite_desc, tup);
{
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);
}
heap_freetuple(tup); heap_freetuple(tup);
...@@ -486,17 +477,8 @@ RenameRewriteRule(Oid owningRel, const char *oldName, ...@@ -486,17 +477,8 @@ RenameRewriteRule(Oid owningRel, const char *oldName,
simple_heap_update(pg_rewrite_desc, &ruletup->t_self, ruletup); simple_heap_update(pg_rewrite_desc, &ruletup->t_self, ruletup);
/* keep system catalog indices current */ /* keep system catalog indexes current */
if (RelationGetForm(pg_rewrite_desc)->relhasindex) CatalogUpdateIndexes(pg_rewrite_desc, ruletup);
{
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);
}
heap_freetuple(ruletup); heap_freetuple(ruletup);
heap_close(pg_rewrite_desc, RowExclusiveLock); heap_close(pg_rewrite_desc, RowExclusiveLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -55,7 +55,6 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules, ...@@ -55,7 +55,6 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules,
Relation relationRelation; Relation relationRelation;
HeapTuple tuple; HeapTuple tuple;
Form_pg_class classForm; Form_pg_class classForm;
Relation idescs[Num_pg_class_indices];
/* /*
* Find the tuple to update in pg_class, using syscache for the * Find the tuple to update in pg_class, using syscache for the
...@@ -79,10 +78,8 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules, ...@@ -79,10 +78,8 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules,
simple_heap_update(relationRelation, &tuple->t_self, tuple); simple_heap_update(relationRelation, &tuple->t_self, tuple);
/* Keep the catalog indices up to date */ /* Keep the catalog indexes up to date */
CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs); CatalogUpdateIndexes(relationRelation, tuple);
CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
CatalogCloseIndices(Num_pg_class_indices, idescs);
} }
else else
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -404,8 +404,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes) ...@@ -404,8 +404,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
Datum values[Natts_pg_largeobject]; Datum values[Natts_pg_largeobject];
char nulls[Natts_pg_largeobject]; char nulls[Natts_pg_largeobject];
char replace[Natts_pg_largeobject]; char replace[Natts_pg_largeobject];
bool write_indices; CatalogIndexState indstate;
Relation idescs[Num_pg_largeobject_indices];
Assert(PointerIsValid(obj_desc)); Assert(PointerIsValid(obj_desc));
Assert(buf != NULL); Assert(buf != NULL);
...@@ -413,11 +412,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes) ...@@ -413,11 +412,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
if (nbytes <= 0) if (nbytes <= 0)
return 0; return 0;
write_indices = !IsIgnoringSystemIndexes(); indstate = CatalogOpenIndexes(obj_desc->heap_r);
if (write_indices)
CatalogOpenIndices(Num_pg_largeobject_indices,
Name_pg_largeobject_indices,
idescs);
ScanKeyEntryInitialize(&skey[0], ScanKeyEntryInitialize(&skey[0],
(bits16) 0x0, (bits16) 0x0,
...@@ -511,9 +506,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes) ...@@ -511,9 +506,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
newtup = heap_modifytuple(oldtuple, obj_desc->heap_r, newtup = heap_modifytuple(oldtuple, obj_desc->heap_r,
values, nulls, replace); values, nulls, replace);
simple_heap_update(obj_desc->heap_r, &newtup->t_self, newtup); simple_heap_update(obj_desc->heap_r, &newtup->t_self, newtup);
if (write_indices) CatalogIndexInsert(indstate, newtup);
CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
obj_desc->heap_r, newtup);
heap_freetuple(newtup); heap_freetuple(newtup);
/* /*
...@@ -556,9 +549,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes) ...@@ -556,9 +549,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
values[Anum_pg_largeobject_data - 1] = PointerGetDatum(&workbuf); values[Anum_pg_largeobject_data - 1] = PointerGetDatum(&workbuf);
newtup = heap_formtuple(obj_desc->heap_r->rd_att, values, nulls); newtup = heap_formtuple(obj_desc->heap_r->rd_att, values, nulls);
simple_heap_insert(obj_desc->heap_r, newtup); simple_heap_insert(obj_desc->heap_r, newtup);
if (write_indices) CatalogIndexInsert(indstate, newtup);
CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
obj_desc->heap_r, newtup);
heap_freetuple(newtup); heap_freetuple(newtup);
} }
pageno++; pageno++;
...@@ -566,8 +557,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes) ...@@ -566,8 +557,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
index_endscan(sd); index_endscan(sd);
if (write_indices) CatalogCloseIndexes(indstate);
CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
/* /*
* Advance command counter so that my tuple updates will be seen by * Advance command counter so that my tuple updates will be seen by
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -118,14 +118,8 @@ SetDefine(char *querystr, Oid elemType) ...@@ -118,14 +118,8 @@ SetDefine(char *querystr, Oid elemType)
AssertTupleDescHasOid(procrel->rd_att); AssertTupleDescHasOid(procrel->rd_att);
setoid = HeapTupleGetOid(newtup); setoid = HeapTupleGetOid(newtup);
if (RelationGetForm(procrel)->relhasindex) CatalogUpdateIndexes(procrel, newtup);
{
Relation idescs[Num_pg_proc_indices];
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); heap_freetuple(newtup);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* These routines allow the parser/planner/executor to perform * These routines allow the parser/planner/executor to perform
...@@ -64,18 +64,16 @@ ...@@ -64,18 +64,16 @@
This is used by CatalogCacheFlushRelation() to remove the correct This is used by CatalogCacheFlushRelation() to remove the correct
tuples during a table drop or relcache invalidation event. tuples during a table drop or relcache invalidation event.
In include/catalog/indexing.h, add a define for the number of indexes There must be a unique index underlying each syscache (ie, an index
on the relation, add define(s) for the index name(s), add an extern whose key is the same as that of the cache). If there is not one
array to hold the index names, and use DECLARE_UNIQUE_INDEX to define already, add definitions for it to include/catalog/indexing.h: you
the index. Cache lookups return only one row, so the index should be need a #define for the index name and a DECLARE_UNIQUE_INDEX macro
unique in most cases. with the actual declaration. (This will require a catversion.h update,
while simply adding/deleting caches only requires a recompile.)
In backend/catalog/indexing.c, initialize the relation array with
the index names for the relation.
Finally, any place your relation gets heap_insert() or Finally, any place your relation gets heap_insert() or
heap_update calls, include code to do a CatalogIndexInsert() to update heap_update calls, make sure there is a CatalogUpdateIndexes() or
the system indexes. The heap_* calls do not update indexes. similar call. The heap_* calls do not update indexes.
bjm 1999/11/22 bjm 1999/11/22
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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 $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,38 +18,10 @@ ...@@ -18,38 +18,10 @@
#include "access/htup.h" #include "access/htup.h"
/* /*
* Number of indices that exist for each system catalog * Names of indexes on system catalogs
*/ *
#define Num_pg_aggregate_indices 1 * References to specific system indexes in the C code should use these
#define Num_pg_am_indices 2 * macros rather than hardwiring the actual index name.
#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
*/ */
#define AccessMethodOperatorIndex "pg_amop_opc_opr_index" #define AccessMethodOperatorIndex "pg_amop_opc_opr_index"
#define AccessMethodStrategyIndex "pg_amop_opc_strategy_index" #define AccessMethodStrategyIndex "pg_amop_opc_strategy_index"
...@@ -104,43 +76,22 @@ ...@@ -104,43 +76,22 @@
#define TypeNameNspIndex "pg_type_typname_nsp_index" #define TypeNameNspIndex "pg_type_typname_nsp_index"
#define TypeOidIndex "pg_type_oid_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 * indexing.c prototypes
*/ */
extern void CatalogOpenIndices(int nIndices, char **names, Relation *idescs); extern CatalogIndexState CatalogOpenIndexes(Relation heapRel);
extern void CatalogCloseIndices(int nIndices, Relation *idescs); extern void CatalogCloseIndexes(CatalogIndexState indstate);
extern void CatalogIndexInsert(Relation *idescs, int nIndices, extern void CatalogIndexInsert(CatalogIndexState indstate,
Relation heapRelation, HeapTuple heapTuple); HeapTuple heapTuple);
extern void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple);
/* /*
...@@ -221,7 +172,7 @@ DECLARE_UNIQUE_INDEX(pg_trigger_oid_index on pg_trigger using btree(oid oid_ops) ...@@ -221,7 +172,7 @@ DECLARE_UNIQUE_INDEX(pg_trigger_oid_index on pg_trigger using btree(oid oid_ops)
DECLARE_UNIQUE_INDEX(pg_type_oid_index on pg_type using btree(oid oid_ops)); 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)); 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 BUILD_INDICES
#endif /* INDEXING_H */ #endif /* INDEXING_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment