OSDN Git Service

Restructure system-catalog index updating logic. Instead of having
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 5 Aug 2002 03:29:17 +0000 (03:29 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 5 Aug 2002 03:29:17 +0000 (03:29 +0000)
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.

29 files changed:
src/backend/catalog/aclchk.c
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/catalog/indexing.c
src/backend/catalog/pg_aggregate.c
src/backend/catalog/pg_constraint.c
src/backend/catalog/pg_conversion.c
src/backend/catalog/pg_depend.c
src/backend/catalog/pg_largeobject.c
src/backend/catalog/pg_namespace.c
src/backend/catalog/pg_operator.c
src/backend/catalog/pg_proc.c
src/backend/catalog/pg_type.c
src/backend/commands/analyze.c
src/backend/commands/async.c
src/backend/commands/comment.c
src/backend/commands/dbcommands.c
src/backend/commands/functioncmds.c
src/backend/commands/opclasscmds.c
src/backend/commands/proclang.c
src/backend/commands/tablecmds.c
src/backend/commands/trigger.c
src/backend/commands/user.c
src/backend/rewrite/rewriteDefine.c
src/backend/rewrite/rewriteSupport.c
src/backend/storage/large_object/inv_api.c
src/backend/utils/adt/sets.c
src/backend/utils/cache/syscache.c
src/include/catalog/indexing.h

index e06065e..c06b42c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.72 2002/07/29 22:14:10 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.73 2002/08/05 03:29:16 tgl Exp $
  *
  * NOTES
  *       See acl.h.
@@ -236,15 +236,8 @@ ExecuteGrantStmt_Relation(GrantStmt *stmt)
 
                simple_heap_update(relation, &newtuple->t_self, newtuple);
 
-               {
-                       /* keep the catalog indexes up to date */
-                       Relation        idescs[Num_pg_class_indices];
-
-                       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_class_indices, relation, newtuple);
-                       CatalogCloseIndices(Num_pg_class_indices, idescs);
-               }
+               /* keep the catalog indexes up to date */
+               CatalogUpdateIndexes(relation, newtuple);
 
                pfree(old_acl);
                pfree(new_acl);
@@ -332,15 +325,8 @@ ExecuteGrantStmt_Database(GrantStmt *stmt)
 
                simple_heap_update(relation, &newtuple->t_self, newtuple);
 
-               {
-                       /* keep the catalog indexes up to date */
-                       Relation        idescs[Num_pg_database_indices];
-
-                       CatalogOpenIndices(Num_pg_database_indices, Name_pg_database_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_database_indices, relation, newtuple);
-                       CatalogCloseIndices(Num_pg_database_indices, idescs);
-               }
+               /* keep the catalog indexes up to date */
+               CatalogUpdateIndexes(relation, newtuple);
 
                pfree(old_acl);
                pfree(new_acl);
@@ -434,15 +420,8 @@ ExecuteGrantStmt_Function(GrantStmt *stmt)
 
                simple_heap_update(relation, &newtuple->t_self, newtuple);
 
-               {
-                       /* keep the catalog indexes up to date */
-                       Relation        idescs[Num_pg_proc_indices];
-
-                       CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_proc_indices, relation, newtuple);
-                       CatalogCloseIndices(Num_pg_proc_indices, idescs);
-               }
+               /* keep the catalog indexes up to date */
+               CatalogUpdateIndexes(relation, newtuple);
 
                pfree(old_acl);
                pfree(new_acl);
@@ -531,15 +510,8 @@ ExecuteGrantStmt_Language(GrantStmt *stmt)
 
                simple_heap_update(relation, &newtuple->t_self, newtuple);
 
-               {
-                       /* keep the catalog indexes up to date */
-                       Relation        idescs[Num_pg_language_indices];
-
-                       CatalogOpenIndices(Num_pg_language_indices, Name_pg_language_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_language_indices, relation, newtuple);
-                       CatalogCloseIndices(Num_pg_language_indices, idescs);
-               }
+               /* keep the catalog indexes up to date */
+               CatalogUpdateIndexes(relation, newtuple);
 
                pfree(old_acl);
                pfree(new_acl);
@@ -628,15 +600,8 @@ ExecuteGrantStmt_Namespace(GrantStmt *stmt)
 
                simple_heap_update(relation, &newtuple->t_self, newtuple);
 
-               {
-                       /* keep the catalog indexes up to date */
-                       Relation        idescs[Num_pg_namespace_indices];
-
-                       CatalogOpenIndices(Num_pg_namespace_indices, Name_pg_namespace_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_namespace_indices, relation, newtuple);
-                       CatalogCloseIndices(Num_pg_namespace_indices, idescs);
-               }
+               /* keep the catalog indexes up to date */
+               CatalogUpdateIndexes(relation, newtuple);
 
                pfree(old_acl);
                pfree(new_acl);
index 65f7dc0..b61ad73 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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
@@ -423,23 +423,17 @@ AddNewAttributeTuples(Oid new_rel_oid,
        int                     i;
        HeapTuple       tup;
        Relation        rel;
-       bool            hasindex;
-       Relation        idescs[Num_pg_attr_indices];
+       CatalogIndexState indstate;
        int                     natts = tupdesc->natts;
        ObjectAddress   myself,
                                        referenced;
 
        /*
-        * open pg_attribute
+        * open pg_attribute and its indexes.
         */
        rel = heap_openr(AttributeRelationName, RowExclusiveLock);
 
-       /*
-        * Check if we have any indices defined on pg_attribute.
-        */
-       hasindex = RelationGetForm(rel)->relhasindex;
-       if (hasindex)
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
+       indstate = CatalogOpenIndexes(rel);
 
        /*
         * First we add the user attributes.  This is also a convenient place
@@ -461,8 +455,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
 
                simple_heap_insert(rel, tup);
 
-               if (hasindex)
-                       CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
+               CatalogIndexInsert(indstate, tup);
 
                heap_freetuple(tup);
 
@@ -509,8 +502,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
 
                                simple_heap_insert(rel, tup);
 
-                               if (hasindex)
-                                       CatalogIndexInsert(idescs, Num_pg_attr_indices, rel, tup);
+                               CatalogIndexInsert(indstate, tup);
 
                                heap_freetuple(tup);
                        }
@@ -521,8 +513,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
        /*
         * clean up
         */
-       if (hasindex)
-               CatalogCloseIndices(Num_pg_attr_indices, idescs);
+       CatalogCloseIndexes(indstate);
 
        heap_close(rel, RowExclusiveLock);
 }
@@ -543,7 +534,6 @@ AddNewRelationTuple(Relation pg_class_desc,
 {
        Form_pg_class new_rel_reltup;
        HeapTuple       tup;
-       Relation        idescs[Num_pg_class_indices];
 
        /*
         * first we update some of the information in our uncataloged
@@ -606,20 +596,11 @@ AddNewRelationTuple(Relation pg_class_desc,
        HeapTupleSetOid(tup, new_rel_oid);
 
        /*
-        * finally insert the new tuple and free it.
+        * finally insert the new tuple, update the indexes, and clean up.
         */
        simple_heap_insert(pg_class_desc, tup);
 
-       if (!IsIgnoringSystemIndexes())
-       {
-               /*
-                * First, open the catalog indices and insert index tuples for the
-                * new relation.
-                */
-               CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class_desc, tup);
-               CatalogCloseIndices(Num_pg_class_indices, idescs);
-       }
+       CatalogUpdateIndexes(pg_class_desc, tup);
 
        heap_freetuple(tup);
 }
@@ -953,15 +934,8 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
 
        simple_heap_update(attr_rel, &tuple->t_self, tuple);
 
-       /* keep the system catalog indices current */
-       if (RelationGetForm(attr_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_attr_indices];
-
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
-               CatalogCloseIndices(Num_pg_attr_indices, idescs);
-       }
+       /* keep the system catalog indexes current */
+       CatalogUpdateIndexes(attr_rel, tuple);
 
        /*
         * Because updating the pg_attribute row will trigger a relcache flush
@@ -1087,15 +1061,8 @@ RemoveAttrDefaultById(Oid attrdefId)
 
        simple_heap_update(attr_rel, &tuple->t_self, tuple);
 
-       /* keep the system catalog indices current */
-       if (RelationGetForm(attr_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_attr_indices];
-
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
-               CatalogCloseIndices(Num_pg_attr_indices, idescs);
-       }
+       /* keep the system catalog indexes current */
+       CatalogUpdateIndexes(attr_rel, tuple);
 
        /*
         * Our update of the pg_attribute row will force a relcache rebuild,
@@ -1195,12 +1162,10 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
        Node       *expr;
        char       *adsrc;
        Relation        adrel;
-       Relation        idescs[Num_pg_attrdef_indices];
        HeapTuple       tuple;
        Datum           values[4];
        static char nulls[4] = {' ', ' ', ' ', ' '};
        Relation        attrrel;
-       Relation        attridescs[Num_pg_attr_indices];
        HeapTuple       atttup;
        Form_pg_attribute attStruct;
        Oid                     attrdefOid;
@@ -1235,10 +1200,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
        tuple = heap_formtuple(adrel->rd_att, values, nulls);
        attrdefOid = simple_heap_insert(adrel, tuple);
 
-       CatalogOpenIndices(Num_pg_attrdef_indices, Name_pg_attrdef_indices,
-                                          idescs);
-       CatalogIndexInsert(idescs, Num_pg_attrdef_indices, adrel, tuple);
-       CatalogCloseIndices(Num_pg_attrdef_indices, idescs);
+       CatalogUpdateIndexes(adrel, tuple);
 
        defobject.classId = RelationGetRelid(adrel);
        defobject.objectId = attrdefOid;
@@ -1269,11 +1231,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
        {
                attStruct->atthasdef = true;
                simple_heap_update(attrrel, &atttup->t_self, atttup);
-               /* keep catalog indices current */
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices,
-                                                  attridescs);
-               CatalogIndexInsert(attridescs, Num_pg_attr_indices, attrrel, atttup);
-               CatalogCloseIndices(Num_pg_attr_indices, attridescs);
+               /* keep catalog indexes current */
+               CatalogUpdateIndexes(attrrel, atttup);
        }
        heap_close(attrrel, RowExclusiveLock);
        heap_freetuple(atttup);
@@ -1655,7 +1614,6 @@ SetRelationNumChecks(Relation rel, int numchecks)
        Relation        relrel;
        HeapTuple       reltup;
        Form_pg_class relStruct;
-       Relation        relidescs[Num_pg_class_indices];
 
        relrel = heap_openr(RelationRelationName, RowExclusiveLock);
        reltup = SearchSysCacheCopy(RELOID,
@@ -1672,11 +1630,8 @@ SetRelationNumChecks(Relation rel, int numchecks)
 
                simple_heap_update(relrel, &reltup->t_self, reltup);
 
-               /* keep catalog indices current */
-               CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
-                                                  relidescs);
-               CatalogIndexInsert(relidescs, Num_pg_class_indices, relrel, reltup);
-               CatalogCloseIndices(Num_pg_class_indices, relidescs);
+               /* keep catalog indexes current */
+               CatalogUpdateIndexes(relrel, reltup);
        }
        else
        {
@@ -1866,9 +1821,9 @@ RemoveStatistics(Relation rel)
 
 /*
  * RelationTruncateIndexes - truncate all
- * indices associated with the heap relation to zero tuples.
+ * indexes associated with the heap relation to zero tuples.
  *
- * The routine will truncate and then reconstruct the indices on
+ * The routine will truncate and then reconstruct the indexes on
  * the relation specified by the heapId parameter.
  */
 static void
index 38fe5cd..e75df63 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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
@@ -314,7 +314,6 @@ UpdateRelationRelation(Relation indexRelation)
 {
        Relation        pg_class;
        HeapTuple       tuple;
-       Relation        idescs[Num_pg_class_indices];
 
        pg_class = heap_openr(RelationRelationName, RowExclusiveLock);
 
@@ -332,18 +331,8 @@ UpdateRelationRelation(Relation indexRelation)
        HeapTupleSetOid(tuple, RelationGetRelid(indexRelation));
        simple_heap_insert(pg_class, tuple);
 
-       /*
-        * During normal processing, we need to make sure that the system
-        * catalog indices are correct.  Bootstrap (initdb) time doesn't
-        * require this, because we make sure that the indices are correct
-        * just before exiting.
-        */
-       if (!IsIgnoringSystemIndexes())
-       {
-               CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, tuple);
-               CatalogCloseIndices(Num_pg_class_indices, idescs);
-       }
+       /* update the system catalog indexes */
+       CatalogUpdateIndexes(pg_class, tuple);
 
        heap_freetuple(tuple);
        heap_close(pg_class, RowExclusiveLock);
@@ -375,23 +364,17 @@ static void
 AppendAttributeTuples(Relation indexRelation, int numatts)
 {
        Relation        pg_attribute;
-       bool            hasind;
-       Relation        idescs[Num_pg_attr_indices];
+       CatalogIndexState indstate;
        TupleDesc       indexTupDesc;
        HeapTuple       new_tuple;
        int                     i;
 
        /*
-        * open the attribute relation
+        * open the attribute relation and its indexes
         */
        pg_attribute = heap_openr(AttributeRelationName, RowExclusiveLock);
 
-       hasind = false;
-       if (!IsIgnoringSystemIndexes() && pg_attribute->rd_rel->relhasindex)
-       {
-               hasind = true;
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
-       }
+       indstate = CatalogOpenIndexes(pg_attribute);
 
        /*
         * insert data from new index's tupdesc into pg_attribute
@@ -414,14 +397,12 @@ AppendAttributeTuples(Relation indexRelation, int numatts)
 
                simple_heap_insert(pg_attribute, new_tuple);
 
-               if (hasind)
-                       CatalogIndexInsert(idescs, Num_pg_attr_indices, pg_attribute, new_tuple);
+               CatalogIndexInsert(indstate, new_tuple);
 
                heap_freetuple(new_tuple);
        }
 
-       if (hasind)
-               CatalogCloseIndices(Num_pg_attr_indices, idescs);
+       CatalogCloseIndexes(indstate);
 
        heap_close(pg_attribute, RowExclusiveLock);
 }
@@ -445,7 +426,6 @@ UpdateIndexRelation(Oid indexoid,
        Relation        pg_index;
        HeapTuple       tuple;
        int                     i;
-       Relation        idescs[Num_pg_index_indices];
 
        /*
         * allocate a Form_pg_index big enough to hold the index-predicate (if
@@ -503,19 +483,12 @@ UpdateIndexRelation(Oid indexoid,
                                                   (void *) indexForm);
 
        /*
-        * insert the tuple into the pg_index
+        * insert the tuple into the pg_index catalog
         */
        simple_heap_insert(pg_index, tuple);
 
-       /*
-        * add index tuples for it
-        */
-       if (!IsIgnoringSystemIndexes())
-       {
-               CatalogOpenIndices(Num_pg_index_indices, Name_pg_index_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_index_indices, pg_index, tuple);
-               CatalogCloseIndices(Num_pg_index_indices, idescs);
-       }
+       /* update the indexes on pg_index */
+       CatalogUpdateIndexes(pg_index, tuple);
 
        /*
         * close the relation and free the tuple
@@ -774,7 +747,7 @@ index_create(Oid heapRelationId,
 
        /*
         * If this is bootstrap (initdb) time, then we don't actually fill in
-        * the index yet.  We'll be creating more indices and classes later,
+        * the index yet.  We'll be creating more indexes and classes later,
         * so we delay filling them in until just before we're done with
         * bootstrapping.  Otherwise, we call the routine that constructs the
         * index.
@@ -1245,16 +1218,8 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid)
        {
                simple_heap_update(pg_class, &tuple->t_self, tuple);
 
-               /* Keep the catalog indices up to date */
-               if (!IsIgnoringSystemIndexes())
-               {
-                       Relation        idescs[Num_pg_class_indices];
-
-                       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, tuple);
-                       CatalogCloseIndices(Num_pg_class_indices, idescs);
-               }
+               /* Keep the catalog indexes up to date */
+               CatalogUpdateIndexes(pg_class, tuple);
        }
        else
        {
@@ -1273,8 +1238,7 @@ setRelhasindex(Oid relid, bool hasindex, bool isprimary, Oid reltoastidxid)
 void
 setNewRelfilenode(Relation relation)
 {
-       Relation        pg_class,
-                               idescs[Num_pg_class_indices];
+       Relation        pg_class;
        Oid                     newrelfilenode;
        bool            in_place_update = false;
        HeapTupleData lockTupleData;
@@ -1321,14 +1285,10 @@ setNewRelfilenode(Relation relation)
                WriteBuffer(buffer);
                BufferSync();
        }
-       /* Keep the catalog indices up to date */
-       if (!in_place_update && pg_class->rd_rel->relhasindex)
-       {
-               CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices,
-                                                  idescs);
-               CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, classTuple);
-               CatalogCloseIndices(Num_pg_class_indices, idescs);
-       }
+       /* Keep the catalog indexes up to date */
+       if (!in_place_update)
+               CatalogUpdateIndexes(pg_class, classTuple);
+
        heap_close(pg_class, NoLock);
        if (!in_place_update)
                heap_freetuple(classTuple);
@@ -1355,7 +1315,6 @@ UpdateStats(Oid relid, double reltuples)
        BlockNumber relpages;
        int                     i;
        Form_pg_class rd_rel;
-       Relation        idescs[Num_pg_class_indices];
        Datum           values[Natts_pg_class];
        char            nulls[Natts_pg_class];
        char            replace[Natts_pg_class];
@@ -1494,12 +1453,7 @@ UpdateStats(Oid relid, double reltuples)
                values[Anum_pg_class_reltuples - 1] = Float4GetDatum((float4) reltuples);
                newtup = heap_modifytuple(tuple, pg_class, values, nulls, replace);
                simple_heap_update(pg_class, &tuple->t_self, newtup);
-               if (!IsIgnoringSystemIndexes())
-               {
-                       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
-                       CatalogIndexInsert(idescs, Num_pg_class_indices, pg_class, newtup);
-                       CatalogCloseIndices(Num_pg_class_indices, idescs);
-               }
+               CatalogUpdateIndexes(pg_class, newtup);
                heap_freetuple(newtup);
        }
 
index 928949d..7f558b4 100644 (file)
@@ -1,7 +1,7 @@
 /*-------------------------------------------------------------------------
  *
  * indexing.c
- *       This file contains routines to support indices defined on system
+ *       This file contains routines to support indexes defined on system
  *       catalogs.
  *
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.99 2002/07/22 20:23:19 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.100 2002/08/05 03:29:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
-
 #include "postgres.h"
 
 #include "access/genam.h"
-#include "access/heapam.h"
-#include "catalog/catalog.h"
-#include "catalog/catname.h"
 #include "catalog/index.h"
 #include "catalog/indexing.h"
-#include "catalog/pg_index.h"
-#include "miscadmin.h"
-#include "utils/fmgroids.h"
-#include "utils/syscache.h"
-
-/*
- * Names of indices for each system catalog.
- */
-
-char      *Name_pg_aggregate_indices[Num_pg_aggregate_indices] =
-{AggregateFnoidIndex};
-char      *Name_pg_am_indices[Num_pg_am_indices] =
-{AmNameIndex, AmOidIndex};
-char      *Name_pg_amop_indices[Num_pg_amop_indices] =
-{AccessMethodOperatorIndex, AccessMethodStrategyIndex};
-char      *Name_pg_amproc_indices[Num_pg_amproc_indices] =
-{AccessMethodProcedureIndex};
-char      *Name_pg_attr_indices[Num_pg_attr_indices] =
-{AttributeRelidNameIndex, AttributeRelidNumIndex};
-char      *Name_pg_attrdef_indices[Num_pg_attrdef_indices] =
-{AttrDefaultIndex, AttrDefaultOidIndex};
-char      *Name_pg_cast_indices[Num_pg_cast_indices] =
-{CastOidIndex, CastSourceTargetIndex};
-char      *Name_pg_class_indices[Num_pg_class_indices] =
-{ClassNameNspIndex, ClassOidIndex};
-char      *Name_pg_constraint_indices[Num_pg_constraint_indices] =
-{ConstraintNameNspIndex, ConstraintOidIndex, ConstraintRelidIndex};
-char      *Name_pg_conversion_indices[Num_pg_conversion_indices] =
-{ConversionDefaultIndex, ConversionNameNspIndex, ConversionOidIndex};
-char      *Name_pg_database_indices[Num_pg_database_indices] =
-{DatabaseNameIndex, DatabaseOidIndex};
-char      *Name_pg_depend_indices[Num_pg_depend_indices] =
-{DependDependerIndex, DependReferenceIndex};
-char      *Name_pg_group_indices[Num_pg_group_indices] =
-{GroupNameIndex, GroupSysidIndex};
-char      *Name_pg_index_indices[Num_pg_index_indices] =
-{IndexRelidIndex, IndexIndrelidIndex};
-char      *Name_pg_inherits_indices[Num_pg_inherits_indices] =
-{InheritsRelidSeqnoIndex};
-char      *Name_pg_language_indices[Num_pg_language_indices] =
-{LanguageOidIndex, LanguageNameIndex};
-char      *Name_pg_largeobject_indices[Num_pg_largeobject_indices] =
-{LargeObjectLOidPNIndex};
-char      *Name_pg_namespace_indices[Num_pg_namespace_indices] =
-{NamespaceNameIndex, NamespaceOidIndex};
-char      *Name_pg_opclass_indices[Num_pg_opclass_indices] =
-{OpclassAmNameNspIndex, OpclassOidIndex};
-char      *Name_pg_operator_indices[Num_pg_operator_indices] =
-{OperatorOidIndex, OperatorNameNspIndex};
-char      *Name_pg_proc_indices[Num_pg_proc_indices] =
-{ProcedureOidIndex, ProcedureNameNspIndex};
-char      *Name_pg_rewrite_indices[Num_pg_rewrite_indices] =
-{RewriteOidIndex, RewriteRelRulenameIndex};
-char      *Name_pg_shadow_indices[Num_pg_shadow_indices] =
-{ShadowNameIndex, ShadowSysidIndex};
-char      *Name_pg_statistic_indices[Num_pg_statistic_indices] =
-{StatisticRelidAttnumIndex};
-char      *Name_pg_trigger_indices[Num_pg_trigger_indices] =
-{TriggerRelidNameIndex, TriggerConstrNameIndex, TriggerConstrRelidIndex, TriggerOidIndex};
-char      *Name_pg_type_indices[Num_pg_type_indices] =
-{TypeNameNspIndex, TypeOidIndex};
-char      *Name_pg_description_indices[Num_pg_description_indices] =
-{DescriptionObjIndex};
-
+#include "executor/executor.h"
 
 
 /*
- * Changes (appends) to catalogs can and do happen at various places
- * throughout the code.  We need a generic routine that will open all of
- * the indices defined on a given catalog and return the relation descriptors
- * associated with them.
+ * CatalogOpenIndexes - open the indexes on a system catalog.
+ *
+ * When inserting or updating tuples in a system catalog, call this
+ * to prepare to update the indexes for the catalog.
+ *
+ * In the current implementation, we share code for opening/closing the
+ * indexes with execUtils.c.  But we do not use ExecInsertIndexTuples,
+ * because we don't want to create an EState.  This implies that we
+ * do not support partial indexes on system catalogs.  Nor do we handle
+ * functional indexes very well (the code will work, but will leak memory
+ * intraquery, because the index function is called in the per-query context
+ * that we are invoked in).  This could be fixed with localized changes here
+ * if we wanted to pay the extra overhead of building an EState.
  */
-void
-CatalogOpenIndices(int nIndices, char **names, Relation *idescs)
+CatalogIndexState
+CatalogOpenIndexes(Relation heapRel)
 {
-       int                     i;
+       ResultRelInfo *resultRelInfo;
 
-       if (IsIgnoringSystemIndexes())
-               return;
-       for (i = 0; i < nIndices; i++)
-               idescs[i] = index_openr(names[i]);
+       resultRelInfo = makeNode(ResultRelInfo);
+       resultRelInfo->ri_RangeTableIndex = 1;          /* dummy */
+       resultRelInfo->ri_RelationDesc = heapRel;
+       resultRelInfo->ri_TrigDesc = NULL; /* we don't fire triggers */
+
+       ExecOpenIndices(resultRelInfo);
+
+       return resultRelInfo;
 }
 
 /*
- * This is the inverse routine to CatalogOpenIndices()
+ * CatalogCloseIndexes - clean up resources allocated by CatalogOpenIndexes
  */
 void
-CatalogCloseIndices(int nIndices, Relation *idescs)
+CatalogCloseIndexes(CatalogIndexState indstate)
 {
-       int                     i;
-
-       if (IsIgnoringSystemIndexes())
-               return;
-       for (i = 0; i < nIndices; i++)
-               index_close(idescs[i]);
+       ExecCloseIndices(indstate);
+       pfree(indstate);
 }
 
-
 /*
- * For the same reasons outlined above for CatalogOpenIndices(), we need a
- * routine that takes a new catalog tuple and inserts an associated index
- * tuple into each catalog index.
+ * CatalogIndexInsert - insert index entries for one catalog tuple
  *
- * NOTE: since this routine looks up all the pg_index data on each call,
- * it's relatively inefficient for inserting a large number of tuples into
- * the same catalog.  We use it only for inserting one or a few tuples
- * in a given command. See ExecOpenIndices() and related routines if you
- * are inserting tuples in bulk.
+ * This should be called for each inserted or updated catalog tuple.
  *
- * NOTE: we do not bother to handle partial indices.  Nor do we try to
- * be efficient for functional indices (the code should work for them,
- * but may leak memory intraquery).  This should be OK for system catalogs,
- * but don't use this routine for user tables!
+ * This is effectively a cut-down version of ExecInsertIndexTuples.
  */
 void
-CatalogIndexInsert(Relation *idescs,
-                                  int nIndices,
-                                  Relation heapRelation,
-                                  HeapTuple heapTuple)
+CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
 {
+       int                     i;
+       int                     numIndexes;
+       RelationPtr relationDescs;
+       Relation        heapRelation;
        TupleDesc       heapDescriptor;
+       IndexInfo **indexInfoArray;
        Datum           datum[INDEX_MAX_KEYS];
        char            nullv[INDEX_MAX_KEYS];
-       int                     i;
 
-       if (IsIgnoringSystemIndexes() || (!heapRelation->rd_rel->relhasindex))
-               return;
+       /*
+        * Get information from the state structure.
+        */
+       numIndexes = indstate->ri_NumIndices;
+       relationDescs = indstate->ri_IndexRelationDescs;
+       indexInfoArray = indstate->ri_IndexRelationInfo;
+       heapRelation = indstate->ri_RelationDesc;
        heapDescriptor = RelationGetDescr(heapRelation);
 
-       for (i = 0; i < nIndices; i++)
+       /*
+        * for each index, form and insert the index tuple
+        */
+       for (i = 0; i < numIndexes; i++)
        {
                IndexInfo  *indexInfo;
-               InsertIndexResult indexRes;
+               InsertIndexResult result;
 
-               indexInfo = BuildIndexInfo(idescs[i]->rd_index);
+               indexInfo = indexInfoArray[i];
 
+               /* Partial indexes on system catalogs are not supported */
+               Assert(indexInfo->ii_Predicate == NIL);
+
+               /*
+                * FormIndexDatum fills in its datum and null parameters with
+                * attribute information taken from the given heap tuple.
+                */
                FormIndexDatum(indexInfo,
                                           heapTuple,
                                           heapDescriptor,
@@ -165,11 +113,35 @@ CatalogIndexInsert(Relation *idescs,
                                           datum,
                                           nullv);
 
-               indexRes = index_insert(idescs[i], datum, nullv,
-                                                               &heapTuple->t_self, heapRelation,
-                                                               idescs[i]->rd_uniqueindex);
-               if (indexRes)
-                       pfree(indexRes);
-               pfree(indexInfo);
+               /*
+                * The index AM does the rest.
+                */
+               result = index_insert(relationDescs[i], /* index relation */
+                                                         datum,        /* array of heaptuple Datums */
+                                                         nullv,        /* info on nulls */
+                                                         &(heapTuple->t_self),         /* tid of heap tuple */
+                                                         heapRelation,
+                                                         relationDescs[i]->rd_uniqueindex);
+
+               if (result)
+                       pfree(result);
        }
 }
+
+/*
+ * CatalogUpdateIndexes - do all the indexing work for a new catalog tuple
+ *
+ * This is a convenience routine for the common case where we only need
+ * to insert or update a single tuple in a system catalog.  Avoid using it for
+ * multiple tuples, since opening the indexes and building the index info
+ * structures is moderately expensive.
+ */
+void
+CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple)
+{
+       CatalogIndexState       indstate;
+
+       indstate = CatalogOpenIndexes(heapRel);
+       CatalogIndexInsert(indstate, heapTuple);
+       CatalogCloseIndexes(indstate);
+}
index f6a54ab..2f9f83d 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
        tup = heap_formtuple(tupDesc, values, nulls);
        simple_heap_insert(aggdesc, tup);
 
-       if (RelationGetForm(aggdesc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_aggregate_indices];
-
-               CatalogOpenIndices(Num_pg_aggregate_indices, Name_pg_aggregate_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_aggregate_indices, aggdesc, tup);
-               CatalogCloseIndices(Num_pg_aggregate_indices, idescs);
-       }
+       CatalogUpdateIndexes(aggdesc, tup);
 
        heap_close(aggdesc, RowExclusiveLock);
 
index 96784e7..1ac4edb 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
 
        conOid = simple_heap_insert(conDesc, tup);
 
-       /* Handle Indices */
-       if (RelationGetForm(conDesc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_constraint_indices];
-
-               CatalogOpenIndices(Num_pg_constraint_indices, Name_pg_constraint_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_constraint_indices, conDesc, tup);
-               CatalogCloseIndices(Num_pg_constraint_indices, idescs);
-       }
+       /* update catalog indexes */
+       CatalogUpdateIndexes(conDesc, tup);
 
        conobject.classId = RelationGetRelid(conDesc);
        conobject.objectId = conOid;
@@ -426,7 +419,6 @@ RemoveConstraintById(Oid conId)
                        Relation                pgrel;
                        HeapTuple               relTup;
                        Form_pg_class   classForm;
-                       Relation                ridescs[Num_pg_class_indices];
                
                        pgrel = heap_openr(RelationRelationName, RowExclusiveLock);
                        relTup = SearchSysCacheCopy(RELOID,
@@ -444,9 +436,7 @@ RemoveConstraintById(Oid conId)
 
                        simple_heap_update(pgrel, &relTup->t_self, relTup);
 
-                       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
-                       CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, relTup);
-                       CatalogCloseIndices(Num_pg_class_indices, ridescs);
+                       CatalogUpdateIndexes(pgrel, relTup);
 
                        heap_freetuple(relTup);
 
index 3e316e3..c422e33 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
        Assert(OidIsValid(oid));
 
        /* update the index if any */
-       if (RelationGetForm(rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_conversion_indices];
-
-               CatalogOpenIndices(Num_pg_conversion_indices, Name_pg_conversion_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_conversion_indices, rel, tup);
-               CatalogCloseIndices(Num_pg_conversion_indices, idescs);
-       }
+       CatalogUpdateIndexes(rel, tup);
 
        myself.classId = get_system_catalog_relid(ConversionRelationName);
        myself.objectId = HeapTupleGetOid(tup);
index 7319cec..44a0842 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
                                                   DependencyType behavior)
 {
        Relation        dependDesc;
+       CatalogIndexState indstate;
        HeapTuple       tup;
        int                     i;
        char            nulls[Natts_pg_depend];
        Datum           values[Natts_pg_depend];
-       Relation        idescs[Num_pg_depend_indices];
-       bool            indices_opened = false;
 
        if (nreferenced <= 0)
                return;                                 /* nothing to do */
@@ -72,6 +71,9 @@ recordMultipleDependencies(const ObjectAddress *depender,
 
        dependDesc = heap_openr(DependRelationName, RowExclusiveLock);
 
+       /* Don't open indexes unless we need to make an update */
+       indstate = NULL;
+
        memset(nulls, ' ', sizeof(nulls));
 
        for (i = 0; i < nreferenced; i++, referenced++)
@@ -101,22 +103,18 @@ recordMultipleDependencies(const ObjectAddress *depender,
 
                        simple_heap_insert(dependDesc, tup);
 
-                       /*
-                        * Keep indices current
-                        */
-                       if (!indices_opened)
-                       {
-                               CatalogOpenIndices(Num_pg_depend_indices, Name_pg_depend_indices, idescs);
-                               indices_opened = true;
-                       }
-                       CatalogIndexInsert(idescs, Num_pg_depend_indices, dependDesc, tup);
+                       /* keep indexes current */
+                       if (indstate == NULL)
+                               indstate = CatalogOpenIndexes(dependDesc);
+
+                       CatalogIndexInsert(indstate, tup);
 
                        heap_freetuple(tup);
                }
        }
 
-       if (indices_opened)
-               CatalogCloseIndices(Num_pg_depend_indices, idescs);
+       if (indstate != NULL)
+               CatalogCloseIndexes(indstate);
 
        heap_close(dependDesc, RowExclusiveLock);
 }
index d78a6f2..07d5dca 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
 {
        Relation        pg_largeobject;
        HeapTuple       ntup;
-       Relation        idescs[Num_pg_largeobject_indices];
        Datum           values[Natts_pg_largeobject];
        char            nulls[Natts_pg_largeobject];
        int                     i;
@@ -65,15 +64,8 @@ LargeObjectCreate(Oid loid)
         */
        simple_heap_insert(pg_largeobject, ntup);
 
-       /*
-        * Update indices
-        */
-       if (!IsIgnoringSystemIndexes())
-       {
-               CatalogOpenIndices(Num_pg_largeobject_indices, Name_pg_largeobject_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_largeobject_indices, pg_largeobject, ntup);
-               CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
-       }
+       /* Update indexes */
+       CatalogUpdateIndexes(pg_largeobject, ntup);
 
        heap_close(pg_largeobject, RowExclusiveLock);
 
index 55f8f0f..0831ea6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
        tupDesc = nspdesc->rd_att;
 
        tup = heap_formtuple(tupDesc, values, nulls);
+
        nspoid = simple_heap_insert(nspdesc, tup);
        Assert(OidIsValid(nspoid));
 
-       if (RelationGetForm(nspdesc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_namespace_indices];
-
-               CatalogOpenIndices(Num_pg_namespace_indices, Name_pg_namespace_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_namespace_indices, nspdesc, tup);
-               CatalogCloseIndices(Num_pg_namespace_indices, idescs);
-       }
+       CatalogUpdateIndexes(nspdesc, tup);
 
        heap_close(nspdesc, RowExclusiveLock);
 
index 64af6ad..620ec73 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.74 2002/07/24 19:11:08 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.75 2002/08/05 03:29:16 tgl Exp $
  *
  * NOTES
  *       these routines moved here from commands/define.c and somewhat cleaned up.
@@ -263,14 +263,7 @@ OperatorShellMake(const char *operatorName,
         */
        operatorObjectId = simple_heap_insert(pg_operator_desc, tup);
 
-       if (RelationGetForm(pg_operator_desc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_operator_indices];
-
-               CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
-               CatalogCloseIndices(Num_pg_operator_indices, idescs);
-       }
+       CatalogUpdateIndexes(pg_operator_desc, tup);
 
        /* Add dependencies for the entry */
        makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc));
@@ -646,14 +639,7 @@ OperatorCreate(const char *operatorName,
        }
 
        /* Must update the indexes in either case */
-       if (RelationGetForm(pg_operator_desc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_operator_indices];
-
-               CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
-               CatalogCloseIndices(Num_pg_operator_indices, idescs);
-       }
+       CatalogUpdateIndexes(pg_operator_desc, tup);
 
        /* Add dependencies for the entry */
        makeOperatorDependencies(tup, RelationGetRelid(pg_operator_desc));
@@ -815,14 +801,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
 
                                simple_heap_update(pg_operator_desc, &tup->t_self, tup);
 
-                               if (RelationGetForm(pg_operator_desc)->relhasindex)
-                               {
-                                       Relation        idescs[Num_pg_operator_indices];
-
-                                       CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
-                                       CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
-                                       CatalogCloseIndices(Num_pg_operator_indices, idescs);
-                               }
+                               CatalogUpdateIndexes(pg_operator_desc, tup);
                        }
                }
 
@@ -847,14 +826,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
 
                simple_heap_update(pg_operator_desc, &tup->t_self, tup);
 
-               if (RelationGetForm(pg_operator_desc)->relhasindex)
-               {
-                       Relation        idescs[Num_pg_operator_indices];
-
-                       CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
-                       CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
-                       CatalogCloseIndices(Num_pg_operator_indices, idescs);
-               }
+               CatalogUpdateIndexes(pg_operator_desc, tup);
 
                values[Anum_pg_operator_oprcom - 1] = (Datum) NULL;
                replaces[Anum_pg_operator_oprcom - 1] = ' ';
@@ -880,14 +852,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
 
                simple_heap_update(pg_operator_desc, &tup->t_self, tup);
 
-               if (RelationGetForm(pg_operator_desc)->relhasindex)
-               {
-                       Relation        idescs[Num_pg_operator_indices];
-
-                       CatalogOpenIndices(Num_pg_operator_indices, Name_pg_operator_indices, idescs);
-                       CatalogIndexInsert(idescs, Num_pg_operator_indices, pg_operator_desc, tup);
-                       CatalogCloseIndices(Num_pg_operator_indices, idescs);
-               }
+               CatalogUpdateIndexes(pg_operator_desc, tup);
        }
 
        heap_close(pg_operator_desc, RowExclusiveLock);
index 5cc8632..f1b437b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
                is_update = false;
        }
 
-       /* Need to update indices for either the insert or update case */
-       if (RelationGetForm(rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_proc_indices];
-
-               CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_proc_indices, rel, tup);
-               CatalogCloseIndices(Num_pg_proc_indices, idescs);
-       }
+       /* Need to update indexes for either the insert or update case */
+       CatalogUpdateIndexes(rel, tup);
 
        AssertTupleDescHasOid(tupDesc);
        retval = HeapTupleGetOid(tup);
index b3e53f9..d1e90c6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
         */
        typoid = simple_heap_insert(pg_type_desc, tup);
 
-       if (RelationGetForm(pg_type_desc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_type_indices];
-
-               CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tup);
-               CatalogCloseIndices(Num_pg_type_indices, idescs);
-       }
+       CatalogUpdateIndexes(pg_type_desc, tup);
 
        /*
         * clean up and return the type-oid
@@ -280,15 +273,8 @@ TypeCreate(const char *typeName,
                typeObjectId = simple_heap_insert(pg_type_desc, tup);
        }
 
-       /* Update indices (not necessary if bootstrapping) */
-       if (RelationGetForm(pg_type_desc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_type_indices];
-
-               CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tup);
-               CatalogCloseIndices(Num_pg_type_indices, idescs);
-       }
+       /* Update indexes */
+       CatalogUpdateIndexes(pg_type_desc, tup);
 
        /*
         * Create dependencies.  We can/must skip this in bootstrap mode.
@@ -382,7 +368,6 @@ TypeRename(const char *oldTypeName, Oid typeNamespace,
                   const char *newTypeName)
 {
        Relation        pg_type_desc;
-       Relation        idescs[Num_pg_type_indices];
        HeapTuple       tuple;
 
        pg_type_desc = heap_openr(TypeRelationName, RowExclusiveLock);
@@ -404,10 +389,8 @@ TypeRename(const char *oldTypeName, Oid typeNamespace,
 
        simple_heap_update(pg_type_desc, &tuple->t_self, tuple);
 
-       /* update the system catalog indices */
-       CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
-       CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tuple);
-       CatalogCloseIndices(Num_pg_type_indices, idescs);
+       /* update the system catalog indexes */
+       CatalogUpdateIndexes(pg_type_desc, tuple);
 
        heap_freetuple(tuple);
        heap_close(pg_type_desc, RowExclusiveLock);
index 9844a5d..5cabe21 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
                Datum           values[Natts_pg_statistic];
                char            nulls[Natts_pg_statistic];
                char            replaces[Natts_pg_statistic];
-               Relation        irelations[Num_pg_statistic_indices];
 
                /* Ignore attr if we weren't able to collect stats */
                if (!stats->stats_valid)
@@ -1784,11 +1783,8 @@ update_attstats(Oid relid, int natts, VacAttrStats **vacattrstats)
                        simple_heap_insert(sd, stup);
                }
 
-               /* update indices too */
-               CatalogOpenIndices(Num_pg_statistic_indices, Name_pg_statistic_indices,
-                                                  irelations);
-               CatalogIndexInsert(irelations, Num_pg_statistic_indices, sd, stup);
-               CatalogCloseIndices(Num_pg_statistic_indices, irelations);
+               /* update indexes too */
+               CatalogUpdateIndexes(sd, stup);
 
                heap_freetuple(stup);
        }
index 5f40f16..4c7c5f2 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.87 2002/06/20 20:29:26 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.88 2002/08/05 03:29:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -245,14 +245,7 @@ Async_Listen(char *relname, int pid)
        simple_heap_insert(lRel, tuple);
 
 #ifdef NOT_USED                                        /* currently there are no indexes */
-       if (RelationGetForm(lRel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_listener_indices];
-
-               CatalogOpenIndices(Num_pg_listener_indices, Name_pg_listener_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, tuple);
-               CatalogCloseIndices(Num_pg_listener_indices, idescs);
-       }
+       CatalogUpdateIndexes(lRel, tuple);
 #endif
 
        heap_freetuple(tuple);
@@ -529,14 +522,7 @@ AtCommit_Notify(void)
                                simple_heap_update(lRel, &lTuple->t_self, rTuple);
 
 #ifdef NOT_USED                                        /* currently there are no indexes */
-                               if (RelationGetForm(lRel)->relhasindex)
-                               {
-                                       Relation        idescs[Num_pg_listener_indices];
-
-                                       CatalogOpenIndices(Num_pg_listener_indices, Name_pg_listener_indices, idescs);
-                                       CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, rTuple);
-                                       CatalogCloseIndices(Num_pg_listener_indices, idescs);
-                               }
+                               CatalogUpdateIndexes(lRel, rTuple);
 #endif
                        }
                }
@@ -802,14 +788,7 @@ ProcessIncomingNotify(void)
                        simple_heap_update(lRel, &lTuple->t_self, rTuple);
 
 #ifdef NOT_USED                                        /* currently there are no indexes */
-                       if (RelationGetForm(lRel)->relhasindex)
-                       {
-                               Relation        idescs[Num_pg_listener_indices];
-
-                               CatalogOpenIndices(Num_pg_listener_indices, Name_pg_listener_indices, idescs);
-                               CatalogIndexInsert(idescs, Num_pg_listener_indices, lRel, rTuple);
-                               CatalogCloseIndices(Num_pg_listener_indices, idescs);
-                       }
+                       CatalogUpdateIndexes(lRel, rTuple);
 #endif
                }
        }
index 118c2c4..e244a82 100644 (file)
@@ -7,7 +7,7 @@
  * Copyright (c) 1996-2001, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.54 2002/08/02 18:15:05 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.55 2002/08/05 03:29:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -206,19 +206,9 @@ CreateComments(Oid oid, Oid classoid, int32 subid, char *comment)
        }
 
        /* Update indexes, if necessary */
-
        if (newtuple != NULL)
        {
-               if (RelationGetForm(description)->relhasindex)
-               {
-                       Relation        idescs[Num_pg_description_indices];
-
-                       CatalogOpenIndices(Num_pg_description_indices,
-                                                          Name_pg_description_indices, idescs);
-                       CatalogIndexInsert(idescs, Num_pg_description_indices, description,
-                                                          newtuple);
-                       CatalogCloseIndices(Num_pg_description_indices, idescs);
-               }
+               CatalogUpdateIndexes(description, newtuple);
                heap_freetuple(newtuple);
        }
 
index 2c401a6..d043d95 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * 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)
 
        simple_heap_insert(pg_database_rel, tuple);
 
-       /*
-        * Update indexes
-        */
-       if (RelationGetForm(pg_database_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_database_indices];
-
-               CatalogOpenIndices(Num_pg_database_indices,
-                                                  Name_pg_database_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_database_indices, pg_database_rel,
-                                                  tuple);
-               CatalogCloseIndices(Num_pg_database_indices, idescs);
-       }
+       /* Update indexes */
+       CatalogUpdateIndexes(pg_database_rel, tuple);
 
        /* Close pg_database, but keep lock till commit */
        heap_close(pg_database_rel, NoLock);
@@ -562,19 +551,8 @@ AlterDatabaseSet(AlterDatabaseSetStmt *stmt)
        newtuple = heap_modifytuple(tuple, rel, repl_val, repl_null, repl_repl);
        simple_heap_update(rel, &tuple->t_self, newtuple);
 
-       /*
-        * Update indexes
-        */
-       if (RelationGetForm(rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_database_indices];
-
-               CatalogOpenIndices(Num_pg_database_indices,
-                                                  Name_pg_database_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_database_indices, rel,
-                                                  newtuple);
-               CatalogCloseIndices(Num_pg_database_indices, idescs);
-       }
+       /* Update indexes */
+       CatalogUpdateIndexes(rel, newtuple);
 
        heap_endscan(scan);
        heap_close(rel, RowExclusiveLock);
index ea858d5..944ae19 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.15 2002/07/29 23:44:44 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.16 2002/08/05 03:29:16 tgl Exp $
  *
  * DESCRIPTION
  *       These routines take the parse tree and pick out the
@@ -685,16 +685,10 @@ CreateCast(CreateCastStmt *stmt)
                nulls[i] = ' ';
 
        tuple = heap_formtuple(RelationGetDescr(relation), values, nulls);
-       simple_heap_insert(relation, tuple);
 
-       if (RelationGetForm(relation)->relhasindex)
-       {
-               Relation        idescs[Num_pg_cast_indices];
+       simple_heap_insert(relation, tuple);
 
-               CatalogOpenIndices(Num_pg_cast_indices, Name_pg_cast_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_cast_indices, relation, tuple);
-               CatalogCloseIndices(Num_pg_cast_indices, idescs);
-       }
+       CatalogUpdateIndexes(relation, tuple);
 
        myself.classId = RelationGetRelid(relation);
        myself.objectId = HeapTupleGetOid(tuple);
index c56b0e1..f544dc9 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * 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)
 
        opclassoid = simple_heap_insert(rel, tup);
 
-       if (RelationGetForm(rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_opclass_indices];
-
-               CatalogOpenIndices(Num_pg_opclass_indices, Name_pg_opclass_indices,
-                                                  idescs);
-               CatalogIndexInsert(idescs, Num_pg_opclass_indices, rel, tup);
-               CatalogCloseIndices(Num_pg_opclass_indices, idescs);
-       }
+       CatalogUpdateIndexes(rel, tup);
 
        heap_freetuple(tup);
 
@@ -395,15 +387,8 @@ storeOperators(Oid opclassoid, int numOperators,
 
                simple_heap_insert(rel, tup);
 
-               if (RelationGetForm(rel)->relhasindex)
-               {
-                       Relation        idescs[Num_pg_amop_indices];
+               CatalogUpdateIndexes(rel, tup);
 
-                       CatalogOpenIndices(Num_pg_amop_indices, Name_pg_amop_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_amop_indices, rel, tup);
-                       CatalogCloseIndices(Num_pg_amop_indices, idescs);
-               }
                heap_freetuple(tup);
        }
 
@@ -444,15 +429,8 @@ storeProcedures(Oid opclassoid, int numProcs, Oid *procedures)
 
                simple_heap_insert(rel, tup);
 
-               if (RelationGetForm(rel)->relhasindex)
-               {
-                       Relation        idescs[Num_pg_amproc_indices];
+               CatalogUpdateIndexes(rel, tup);
 
-                       CatalogOpenIndices(Num_pg_amproc_indices, Name_pg_amproc_indices,
-                                                          idescs);
-                       CatalogIndexInsert(idescs, Num_pg_amproc_indices, rel, tup);
-                       CatalogCloseIndices(Num_pg_amproc_indices, idescs);
-               }
                heap_freetuple(tup);
        }
 
index 567b59d..0c28dea 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.38 2002/07/24 19:11:09 petere Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.39 2002/08/05 03:29:17 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -119,14 +119,7 @@ CreateProceduralLanguage(CreatePLangStmt *stmt)
 
        simple_heap_insert(rel, tup);
 
-       if (RelationGetForm(rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_language_indices];
-
-               CatalogOpenIndices(Num_pg_language_indices, Name_pg_language_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_language_indices, rel, tup);
-               CatalogCloseIndices(Num_pg_language_indices, idescs);
-       }
+       CatalogUpdateIndexes(rel, tup);
 
        /*
         * Create dependencies for language
index 4972c09..eedc1a9 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
  *                               BadArg if name is invalid
  *
  * Note:
- *                               Rows are removed, indices are truncated and reconstructed.
+ *                               Rows are removed, indexes are truncated and reconstructed.
  */
 void
 TruncateRelation(const RangeVar *relation)
@@ -832,14 +832,7 @@ StoreCatalogInheritance(Oid relationId, List *supers)
 
                simple_heap_insert(relation, tuple);
 
-               if (RelationGetForm(relation)->relhasindex)
-               {
-                       Relation        idescs[Num_pg_inherits_indices];
-
-                       CatalogOpenIndices(Num_pg_inherits_indices, Name_pg_inherits_indices, idescs);
-                       CatalogIndexInsert(idescs, Num_pg_inherits_indices, relation, tuple);
-                       CatalogCloseIndices(Num_pg_inherits_indices, idescs);
-               }
+               CatalogUpdateIndexes(relation, tuple);
 
                heap_freetuple(tuple);
 
@@ -969,7 +962,6 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
 {
        Relation        relationRelation;
        HeapTuple       tuple;
-       Relation        idescs[Num_pg_class_indices];
 
        /*
         * Fetch a modifiable copy of the tuple, modify it, update pg_class.
@@ -984,10 +976,8 @@ setRelhassubclassInRelation(Oid relationId, bool relhassubclass)
        ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass = relhassubclass;
        simple_heap_update(relationRelation, &tuple->t_self, tuple);
 
-       /* keep the catalog indices up to date */
-       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
-       CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
-       CatalogCloseIndices(Num_pg_class_indices, idescs);
+       /* keep the catalog indexes up to date */
+       CatalogUpdateIndexes(relationRelation, tuple);
 
        heap_freetuple(tuple);
        heap_close(relationRelation, RowExclusiveLock);
@@ -1097,14 +1087,8 @@ renameatt(Oid relid,
 
        simple_heap_update(attrelation, &atttup->t_self, atttup);
 
-       /* keep system catalog indices current */
-       {
-               Relation        irelations[Num_pg_attr_indices];
-
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
-               CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, atttup);
-               CatalogCloseIndices(Num_pg_attr_indices, irelations);
-       }
+       /* keep system catalog indexes current */
+       CatalogUpdateIndexes(attrelation, atttup);
 
        heap_freetuple(atttup);
 
@@ -1151,14 +1135,9 @@ renameatt(Oid relid,
 
                simple_heap_update(attrelation, &atttup->t_self, atttup);
 
-               /* keep system catalog indices current */
-               {
-                       Relation        irelations[Num_pg_attr_indices];
+               /* keep system catalog indexes current */
+               CatalogUpdateIndexes(attrelation, atttup);
 
-                       CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
-                       CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, atttup);
-                       CatalogCloseIndices(Num_pg_attr_indices, irelations);
-               }
                heap_freetuple(atttup);
        }
 
@@ -1203,7 +1182,6 @@ renamerel(Oid relid, const char *newrelname)
        char       *oldrelname;
        char            relkind;
        bool            relhastriggers;
-       Relation        irelations[Num_pg_class_indices];
 
        /*
         * Grab an exclusive lock on the target table or index, which we will
@@ -1247,10 +1225,8 @@ renamerel(Oid relid, const char *newrelname)
 
        simple_heap_update(relrelation, &reltup->t_self, reltup);
 
-       /* keep the system catalog indices current */
-       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, irelations);
-       CatalogIndexInsert(irelations, Num_pg_class_indices, relrelation, reltup);
-       CatalogCloseIndices(Num_pg_class_indices, irelations);
+       /* keep the system catalog indexes current */
+       CatalogUpdateIndexes(relrelation, reltup);
 
        heap_close(relrelation, NoLock);
        heap_freetuple(reltup);
@@ -1481,13 +1457,7 @@ update_ri_trigger_args(Oid relid,
                 */
                simple_heap_update(tgrel, &tuple->t_self, tuple);
 
-               {
-                       Relation        irelations[Num_pg_attr_indices];
-
-                       CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, irelations);
-                       CatalogIndexInsert(irelations, Num_pg_trigger_indices, tgrel, tuple);
-                       CatalogCloseIndices(Num_pg_trigger_indices, irelations);
-               }
+               CatalogUpdateIndexes(tgrel, tuple);
 
                /* free up our scratch memory */
                pfree(newtgargs);
@@ -1703,14 +1673,7 @@ AlterTableAddColumn(Oid myrelid,
        simple_heap_insert(attrdesc, attributeTuple);
 
        /* Update indexes on pg_attribute */
-       if (RelationGetForm(attrdesc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_attr_indices];
-
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_attr_indices, attrdesc, attributeTuple);
-               CatalogCloseIndices(Num_pg_attr_indices, idescs);
-       }
+       CatalogUpdateIndexes(attrdesc, attributeTuple);
 
        heap_close(attrdesc, RowExclusiveLock);
 
@@ -1723,15 +1686,8 @@ AlterTableAddColumn(Oid myrelid,
        AssertTupleDescHasOid(pgclass->rd_att);
        simple_heap_update(pgclass, &newreltup->t_self, newreltup);
 
-       /* keep catalog indices current */
-       if (RelationGetForm(pgclass)->relhasindex)
-       {
-               Relation        ridescs[Num_pg_class_indices];
-
-               CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
-               CatalogIndexInsert(ridescs, Num_pg_class_indices, pgclass, newreltup);
-               CatalogCloseIndices(Num_pg_class_indices, ridescs);
-       }
+       /* keep catalog indexes current */
+       CatalogUpdateIndexes(pgclass, newreltup);
 
        heap_freetuple(newreltup);
        ReleaseSysCache(reltup);
@@ -1850,7 +1806,7 @@ AlterTableAlterColumnDropNotNull(Oid myrelid,
         * Check that the attribute is not in a primary key
         */
 
-       /* Loop over all indices on the relation */
+       /* Loop over all indexes on the relation */
        indexoidlist = RelationGetIndexList(rel);
 
        foreach(indexoidscan, indexoidlist)
@@ -1902,15 +1858,8 @@ AlterTableAlterColumnDropNotNull(Oid myrelid,
 
        simple_heap_update(attr_rel, &tuple->t_self, tuple);
 
-       /* keep the system catalog indices current */
-       if (RelationGetForm(attr_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_attr_indices];
-
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
-               CatalogCloseIndices(Num_pg_attr_indices, idescs);
-       }
+       /* keep the system catalog indexes current */
+       CatalogUpdateIndexes(attr_rel, tuple);
 
        heap_close(attr_rel, RowExclusiveLock);
 
@@ -2023,15 +1972,8 @@ AlterTableAlterColumnSetNotNull(Oid myrelid,
 
        simple_heap_update(attr_rel, &tuple->t_self, tuple);
 
-       /* keep the system catalog indices current */
-       if (RelationGetForm(attr_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_attr_indices];
-
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_attr_indices, attr_rel, tuple);
-               CatalogCloseIndices(Num_pg_attr_indices, idescs);
-       }
+       /* keep the system catalog indexes current */
+       CatalogUpdateIndexes(attr_rel, tuple);
 
        heap_close(attr_rel, RowExclusiveLock);
 
@@ -2278,16 +2220,11 @@ AlterTableAlterColumnFlags(Oid myrelid,
 
        simple_heap_update(attrelation, &tuple->t_self, tuple);
 
-       /* keep system catalog indices current */
-       {
-               Relation        irelations[Num_pg_attr_indices];
-
-               CatalogOpenIndices(Num_pg_attr_indices, Name_pg_attr_indices, irelations);
-               CatalogIndexInsert(irelations, Num_pg_attr_indices, attrelation, tuple);
-               CatalogCloseIndices(Num_pg_attr_indices, irelations);
-       }
+       /* keep system catalog indexes current */
+       CatalogUpdateIndexes(attrelation, tuple);
 
        heap_freetuple(tuple);
+
        heap_close(attrelation, NoLock);
        heap_close(rel, NoLock);        /* close rel, but keep lock! */
 }
@@ -3200,7 +3137,6 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId)
        Relation                target_rel;
        Relation                class_rel;
        HeapTuple               tuple;
-       Relation                idescs[Num_pg_class_indices];
        Form_pg_class   tuple_class;
 
        /* Get exclusive lock till end of transaction on the target table */
@@ -3227,10 +3163,8 @@ AlterTableOwner(Oid relationOid, int32 newOwnerSysId)
        tuple_class->relowner = newOwnerSysId;
        simple_heap_update(class_rel, &tuple->t_self, tuple);
 
-       /* Keep the catalog indices up to date */
-       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
-       CatalogIndexInsert(idescs, Num_pg_class_indices, class_rel, tuple);
-       CatalogCloseIndices(Num_pg_class_indices, idescs);
+       /* Keep the catalog indexes up to date */
+       CatalogUpdateIndexes(class_rel, tuple);
 
        /*
         * If we are operating on a table, also change the ownership of any
@@ -3299,7 +3233,6 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
        bool            shared_relation;
        Relation        class_rel;
        Buffer          buffer;
-       Relation        ridescs[Num_pg_class_indices];
        Oid                     toast_relid;
        Oid                     toast_idxid;
        char            toast_relname[NAMEDATALEN];
@@ -3481,14 +3414,11 @@ AlterTableCreateToastTable(Oid relOid, bool silent)
         * Store the toast table's OID in the parent relation's tuple
         */
        ((Form_pg_class) GETSTRUCT(reltup))->reltoastrelid = toast_relid;
+
        simple_heap_update(class_rel, &reltup->t_self, reltup);
 
-       /*
-        * Keep catalog indices current
-        */
-       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
-       CatalogIndexInsert(ridescs, Num_pg_class_indices, class_rel, reltup);
-       CatalogCloseIndices(Num_pg_class_indices, ridescs);
+       /* Keep catalog indexes current */
+       CatalogUpdateIndexes(class_rel, reltup);
 
        heap_freetuple(reltup);
 
index 353d684..7fa5708 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.123 2002/07/20 19:55:38 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.124 2002/08/05 03:29:17 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -72,8 +72,6 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
        ScanKeyData key;
        Relation        pgrel;
        HeapTuple       tuple;
-       Relation        idescs[Num_pg_trigger_indices];
-       Relation        ridescs[Num_pg_class_indices];
        Oid                     fargtypes[FUNC_MAX_ARGS];
        Oid                     funcoid;
        Oid                     funclang;
@@ -302,9 +300,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
         */
        simple_heap_insert(tgrel, tuple);
 
-       CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
-       CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);
-       CatalogCloseIndices(Num_pg_trigger_indices, idescs);
+       CatalogUpdateIndexes(tgrel, tuple);
 
        myself.classId = RelationGetRelid(tgrel);
        myself.objectId = trigoid;
@@ -333,9 +329,7 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint)
 
        simple_heap_update(pgrel, &tuple->t_self, tuple);
 
-       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
-       CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
-       CatalogCloseIndices(Num_pg_class_indices, ridescs);
+       CatalogUpdateIndexes(pgrel, tuple);
 
        heap_freetuple(tuple);
        heap_close(pgrel, RowExclusiveLock);
@@ -447,7 +441,6 @@ RemoveTriggerById(Oid trigOid)
        Relation        pgrel;
        HeapTuple       tuple;
        Form_pg_class   classForm;
-       Relation        ridescs[Num_pg_class_indices];
 
        tgrel = heap_openr(TriggerRelationName, RowExclusiveLock);
 
@@ -514,9 +507,7 @@ RemoveTriggerById(Oid trigOid)
 
        simple_heap_update(pgrel, &tuple->t_self, tuple);
 
-       CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, ridescs);
-       CatalogIndexInsert(ridescs, Num_pg_class_indices, pgrel, tuple);
-       CatalogCloseIndices(Num_pg_class_indices, ridescs);
+       CatalogUpdateIndexes(pgrel, tuple);
 
        heap_freetuple(tuple);
 
@@ -549,7 +540,6 @@ renametrig(Oid relid,
        HeapTuple       tuple;
        SysScanDesc     tgscan;
        ScanKeyData key[2];
-       Relation        idescs[Num_pg_trigger_indices];
 
        /*
         * Grab an exclusive lock on the target table, which we will NOT
@@ -610,12 +600,8 @@ renametrig(Oid relid,
 
                simple_heap_update(tgrel, &tuple->t_self, tuple);
 
-               /*
-                * keep system catalog indices current
-                */
-               CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);
-               CatalogCloseIndices(Num_pg_trigger_indices, idescs);
+               /* keep system catalog indexes current */
+               CatalogUpdateIndexes(tgrel, tuple);
 
                /*
                 * Invalidate relation's relcache entry so that other backends (and
index d464b55..60fc4b7 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.106 2002/07/24 19:11:09 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.107 2002/08/05 03:29:17 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -597,19 +597,8 @@ CreateUser(CreateUserStmt *stmt)
         */
        simple_heap_insert(pg_shadow_rel, tuple);
 
-       /*
-        * Update indexes
-        */
-       if (RelationGetForm(pg_shadow_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_shadow_indices];
-
-               CatalogOpenIndices(Num_pg_shadow_indices,
-                                                  Name_pg_shadow_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_shadow_indices, pg_shadow_rel,
-                                                  tuple);
-               CatalogCloseIndices(Num_pg_shadow_indices, idescs);
-       }
+       /* Update indexes */
+       CatalogUpdateIndexes(pg_shadow_rel, tuple);
 
        /*
         * Add the user to the groups specified. We'll just call the below
@@ -809,16 +798,7 @@ AlterUser(AlterUserStmt *stmt)
        simple_heap_update(pg_shadow_rel, &tuple->t_self, new_tuple);
 
        /* Update indexes */
-       if (RelationGetForm(pg_shadow_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_shadow_indices];
-
-               CatalogOpenIndices(Num_pg_shadow_indices,
-                                                  Name_pg_shadow_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_shadow_indices, pg_shadow_rel,
-                                                  new_tuple);
-               CatalogCloseIndices(Num_pg_shadow_indices, idescs);
-       }
+       CatalogUpdateIndexes(pg_shadow_rel, new_tuple);
 
        ReleaseSysCache(tuple);
        heap_freetuple(new_tuple);
@@ -898,13 +878,7 @@ AlterUserSet(AlterUserSetStmt *stmt)
        newtuple = heap_modifytuple(oldtuple, rel, repl_val, repl_null, repl_repl);
        simple_heap_update(rel, &oldtuple->t_self, newtuple);
 
-       {
-               Relation        idescs[Num_pg_shadow_indices];
-
-               CatalogOpenIndices(Num_pg_shadow_indices, Name_pg_shadow_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_shadow_indices, rel, newtuple);
-               CatalogCloseIndices(Num_pg_shadow_indices, idescs);
-       }
+       CatalogUpdateIndexes(rel, newtuple);
 
        ReleaseSysCache(oldtuple);
        heap_close(rel, RowExclusiveLock);
@@ -1216,19 +1190,8 @@ CreateGroup(CreateGroupStmt *stmt)
         */
        simple_heap_insert(pg_group_rel, tuple);
 
-       /*
-        * Update indexes
-        */
-       if (RelationGetForm(pg_group_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_group_indices];
-
-               CatalogOpenIndices(Num_pg_group_indices,
-                                                  Name_pg_group_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_group_indices, pg_group_rel,
-                                                  tuple);
-               CatalogCloseIndices(Num_pg_group_indices, idescs);
-       }
+       /* Update indexes */
+       CatalogUpdateIndexes(pg_group_rel, tuple);
 
        heap_close(pg_group_rel, NoLock);
 
@@ -1417,16 +1380,7 @@ UpdateGroupMembership(Relation group_rel, HeapTuple group_tuple,
        simple_heap_update(group_rel, &group_tuple->t_self, tuple);
 
        /* Update indexes */
-       if (RelationGetForm(group_rel)->relhasindex)
-       {
-               Relation        idescs[Num_pg_group_indices];
-
-               CatalogOpenIndices(Num_pg_group_indices,
-                                                  Name_pg_group_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_group_indices, group_rel,
-                                                  tuple);
-               CatalogCloseIndices(Num_pg_group_indices, idescs);
-       }
+       CatalogUpdateIndexes(group_rel, tuple);
 }
 
 
index 577ce2b..80952d7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
 
        rewriteObjectId = simple_heap_insert(pg_rewrite_desc, tup);
 
-       if (RelationGetForm(pg_rewrite_desc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_rewrite_indices];
-
-               CatalogOpenIndices(Num_pg_rewrite_indices, Name_pg_rewrite_indices,
-                                                  idescs);
-               CatalogIndexInsert(idescs, Num_pg_rewrite_indices, pg_rewrite_desc,
-                                                  tup);
-               CatalogCloseIndices(Num_pg_rewrite_indices, idescs);
-       }
+       CatalogUpdateIndexes(pg_rewrite_desc, tup);
 
        heap_freetuple(tup);
 
@@ -486,17 +477,8 @@ RenameRewriteRule(Oid owningRel, const char *oldName,
 
        simple_heap_update(pg_rewrite_desc, &ruletup->t_self, ruletup);
 
-       /* keep system catalog indices current */
-       if (RelationGetForm(pg_rewrite_desc)->relhasindex)
-       {
-               Relation        idescs[Num_pg_rewrite_indices];
-
-               CatalogOpenIndices(Num_pg_rewrite_indices, Name_pg_rewrite_indices,
-                                                  idescs);
-               CatalogIndexInsert(idescs, Num_pg_rewrite_indices, pg_rewrite_desc,
-                                                  ruletup);
-               CatalogCloseIndices(Num_pg_rewrite_indices, idescs);
-       }
+       /* keep system catalog indexes current */
+       CatalogUpdateIndexes(pg_rewrite_desc, ruletup);
 
        heap_freetuple(ruletup);
        heap_close(pg_rewrite_desc, RowExclusiveLock);
index 3f4c7f2..e55ceb8 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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,
        Relation        relationRelation;
        HeapTuple       tuple;
        Form_pg_class classForm;
-       Relation        idescs[Num_pg_class_indices];
 
        /*
         * Find the tuple to update in pg_class, using syscache for the
@@ -79,10 +78,8 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules,
 
                simple_heap_update(relationRelation, &tuple->t_self, tuple);
 
-               /* Keep the catalog indices up to date */
-               CatalogOpenIndices(Num_pg_class_indices, Name_pg_class_indices, idescs);
-               CatalogIndexInsert(idescs, Num_pg_class_indices, relationRelation, tuple);
-               CatalogCloseIndices(Num_pg_class_indices, idescs);
+               /* Keep the catalog indexes up to date */
+               CatalogUpdateIndexes(relationRelation, tuple);
        }
        else
        {
index 0e279ee..5279190 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * 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)
        Datum           values[Natts_pg_largeobject];
        char            nulls[Natts_pg_largeobject];
        char            replace[Natts_pg_largeobject];
-       bool            write_indices;
-       Relation        idescs[Num_pg_largeobject_indices];
+       CatalogIndexState indstate;
 
        Assert(PointerIsValid(obj_desc));
        Assert(buf != NULL);
@@ -413,11 +412,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
        if (nbytes <= 0)
                return 0;
 
-       write_indices = !IsIgnoringSystemIndexes();
-       if (write_indices)
-               CatalogOpenIndices(Num_pg_largeobject_indices,
-                                                  Name_pg_largeobject_indices,
-                                                  idescs);
+       indstate = CatalogOpenIndexes(obj_desc->heap_r);
 
        ScanKeyEntryInitialize(&skey[0],
                                                   (bits16) 0x0,
@@ -511,9 +506,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
                        newtup = heap_modifytuple(oldtuple, obj_desc->heap_r,
                                                                          values, nulls, replace);
                        simple_heap_update(obj_desc->heap_r, &newtup->t_self, newtup);
-                       if (write_indices)
-                               CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
-                                                                  obj_desc->heap_r, newtup);
+                       CatalogIndexInsert(indstate, newtup);
                        heap_freetuple(newtup);
 
                        /*
@@ -556,9 +549,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
                        values[Anum_pg_largeobject_data - 1] = PointerGetDatum(&workbuf);
                        newtup = heap_formtuple(obj_desc->heap_r->rd_att, values, nulls);
                        simple_heap_insert(obj_desc->heap_r, newtup);
-                       if (write_indices)
-                               CatalogIndexInsert(idescs, Num_pg_largeobject_indices,
-                                                                  obj_desc->heap_r, newtup);
+                       CatalogIndexInsert(indstate, newtup);
                        heap_freetuple(newtup);
                }
                pageno++;
@@ -566,8 +557,7 @@ inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes)
 
        index_endscan(sd);
 
-       if (write_indices)
-               CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
+       CatalogCloseIndexes(indstate);
 
        /*
         * Advance command counter so that my tuple updates will be seen by
index a9a65fc..609e202 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * 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)
                AssertTupleDescHasOid(procrel->rd_att);
                setoid = HeapTupleGetOid(newtup);
 
-               if (RelationGetForm(procrel)->relhasindex)
-               {
-                       Relation        idescs[Num_pg_proc_indices];
+               CatalogUpdateIndexes(procrel, newtup);
 
-                       CatalogOpenIndices(Num_pg_proc_indices, Name_pg_proc_indices, idescs);
-                       CatalogIndexInsert(idescs, Num_pg_proc_indices, procrel, newtup);
-                       CatalogCloseIndices(Num_pg_proc_indices, idescs);
-               }
                heap_freetuple(newtup);
        }
 
index c9b68b1..357829b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.85 2002/08/02 18:15:08 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.86 2002/08/05 03:29:17 tgl Exp $
  *
  * NOTES
  *       These routines allow the parser/planner/executor to perform
        This is used by CatalogCacheFlushRelation() to remove the correct
        tuples during a table drop or relcache invalidation event.
 
-       In include/catalog/indexing.h, add a define for the number of indexes
-       on the relation, add define(s) for the index name(s), add an extern
-       array to hold the index names, and use DECLARE_UNIQUE_INDEX to define
-       the index.      Cache lookups return only one row, so the index should be
-       unique in most cases.
-
-       In backend/catalog/indexing.c, initialize the relation array with
-       the index names for the relation.
+       There must be a unique index underlying each syscache (ie, an index
+       whose key is the same as that of the cache).  If there is not one
+       already, add definitions for it to include/catalog/indexing.h: you
+       need a #define for the index name and a DECLARE_UNIQUE_INDEX macro
+       with the actual declaration.  (This will require a catversion.h update,
+       while simply adding/deleting caches only requires a recompile.)
 
        Finally, any place your relation gets heap_insert() or
-       heap_update calls, include code to do a CatalogIndexInsert() to update
-       the system indexes.  The heap_* calls do not update indexes.
+       heap_update calls, make sure there is a CatalogUpdateIndexes() or
+       similar call.  The heap_* calls do not update indexes.
 
        bjm 1999/11/22
 
index 4928eda..da512da 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: indexing.h,v 1.73 2002/07/25 10:07:12 ishii Exp $
+ * $Id: indexing.h,v 1.74 2002/08/05 03:29:17 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "access/htup.h"
 
 /*
- * Number of indices that exist for each system catalog
- */
-#define Num_pg_aggregate_indices       1
-#define Num_pg_am_indices                      2
-#define Num_pg_amop_indices                    2
-#define Num_pg_amproc_indices          1
-#define Num_pg_attr_indices                    2
-#define Num_pg_attrdef_indices         2
-#define Num_pg_cast_indices                    2
-#define Num_pg_class_indices           2
-#define Num_pg_constraint_indices      3
-#define Num_pg_conversion_indices      3
-#define Num_pg_database_indices                2
-#define Num_pg_depend_indices          2
-#define Num_pg_description_indices     1
-#define Num_pg_group_indices           2
-#define Num_pg_index_indices           2
-#define Num_pg_inherits_indices                1
-#define Num_pg_language_indices                2
-#define Num_pg_largeobject_indices     1
-#define Num_pg_namespace_indices       2
-#define Num_pg_opclass_indices         2
-#define Num_pg_operator_indices                2
-#define Num_pg_proc_indices                    2
-#define Num_pg_rewrite_indices         2
-#define Num_pg_shadow_indices          2
-#define Num_pg_statistic_indices       1
-#define Num_pg_trigger_indices         4
-#define Num_pg_type_indices                    2
-
-/*
- * Names of indices on system catalogs
+ * Names of indexes on system catalogs
+ *
+ * References to specific system indexes in the C code should use these
+ * macros rather than hardwiring the actual index name.
  */
 #define AccessMethodOperatorIndex      "pg_amop_opc_opr_index"
 #define AccessMethodStrategyIndex      "pg_amop_opc_strategy_index"
 #define TypeNameNspIndex                       "pg_type_typname_nsp_index"
 #define TypeOidIndex                           "pg_type_oid_index"
 
-/* Arrays of names of indices for each system catalog */
-extern char *Name_pg_aggregate_indices[];
-extern char *Name_pg_am_indices[];
-extern char *Name_pg_amop_indices[];
-extern char *Name_pg_amproc_indices[];
-extern char *Name_pg_attr_indices[];
-extern char *Name_pg_attrdef_indices[];
-extern char *Name_pg_cast_indices[];
-extern char *Name_pg_class_indices[];
-extern char *Name_pg_constraint_indices[];
-extern char *Name_pg_conversion_indices[];
-extern char *Name_pg_database_indices[];
-extern char *Name_pg_depend_indices[];
-extern char *Name_pg_description_indices[];
-extern char *Name_pg_group_indices[];
-extern char *Name_pg_index_indices[];
-extern char *Name_pg_inherits_indices[];
-extern char *Name_pg_language_indices[];
-extern char *Name_pg_largeobject_indices[];
-extern char *Name_pg_namespace_indices[];
-extern char *Name_pg_opclass_indices[];
-extern char *Name_pg_operator_indices[];
-extern char *Name_pg_proc_indices[];
-extern char *Name_pg_rewrite_indices[];
-extern char *Name_pg_shadow_indices[];
-extern char *Name_pg_statistic_indices[];
-extern char *Name_pg_trigger_indices[];
-extern char *Name_pg_type_indices[];
 
+/*
+ * The state object used by CatalogOpenIndexes and friends is actually the
+ * same as the executor's ResultRelInfo, but we give it another type name
+ * to decouple callers from that fact.
+ */
+typedef struct ResultRelInfo *CatalogIndexState;
 
 /*
  * indexing.c prototypes
  */
-extern void CatalogOpenIndices(int nIndices, char **names, Relation *idescs);
-extern void CatalogCloseIndices(int nIndices, Relation *idescs);
-extern void CatalogIndexInsert(Relation *idescs, int nIndices,
-                                  Relation heapRelation, HeapTuple heapTuple);
+extern CatalogIndexState CatalogOpenIndexes(Relation heapRel);
+extern void CatalogCloseIndexes(CatalogIndexState indstate);
+extern void CatalogIndexInsert(CatalogIndexState indstate,
+                                                          HeapTuple heapTuple);
+extern void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple);
 
 
 /*
@@ -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_typname_nsp_index on pg_type using btree(typname name_ops, typnamespace oid_ops));
 
-/* last step of initialization script: build the indices declared above */
+/* last step of initialization script: build the indexes declared above */
 BUILD_INDICES
 
 #endif   /* INDEXING_H */