88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.217 2002/08/0502:30:50 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.218 2002/08/0503:29:16 tgl Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
@@ -423,23 +423,17 @@ AddNewAttributeTuples(Oid new_rel_oid,
423423int i ;
424424HeapTuple tup ;
425425Relation rel ;
426- bool hasindex ;
427- Relation idescs [Num_pg_attr_indices ];
426+ CatalogIndexState indstate ;
428427int natts = tupdesc -> natts ;
429428ObjectAddress myself ,
430429referenced ;
431430
432431/*
433- * open pg_attribute
432+ * open pg_attribute and its indexes.
434433 */
435434rel = heap_openr (AttributeRelationName ,RowExclusiveLock );
436435
437- /*
438- * Check if we have any indices defined on pg_attribute.
439- */
440- hasindex = RelationGetForm (rel )-> relhasindex ;
441- if (hasindex )
442- CatalogOpenIndices (Num_pg_attr_indices ,Name_pg_attr_indices ,idescs );
436+ indstate = CatalogOpenIndexes (rel );
443437
444438/*
445439 * First we add the user attributes. This is also a convenient place
@@ -461,8 +455,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
461455
462456simple_heap_insert (rel ,tup );
463457
464- if (hasindex )
465- CatalogIndexInsert (idescs ,Num_pg_attr_indices ,rel ,tup );
458+ CatalogIndexInsert (indstate ,tup );
466459
467460heap_freetuple (tup );
468461
@@ -509,8 +502,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
509502
510503simple_heap_insert (rel ,tup );
511504
512- if (hasindex )
513- CatalogIndexInsert (idescs ,Num_pg_attr_indices ,rel ,tup );
505+ CatalogIndexInsert (indstate ,tup );
514506
515507heap_freetuple (tup );
516508}
@@ -521,8 +513,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
521513/*
522514 * clean up
523515 */
524- if (hasindex )
525- CatalogCloseIndices (Num_pg_attr_indices ,idescs );
516+ CatalogCloseIndexes (indstate );
526517
527518heap_close (rel ,RowExclusiveLock );
528519}
@@ -543,7 +534,6 @@ AddNewRelationTuple(Relation pg_class_desc,
543534{
544535Form_pg_class new_rel_reltup ;
545536HeapTuple tup ;
546- Relation idescs [Num_pg_class_indices ];
547537
548538/*
549539 * first we update some of the information in our uncataloged
@@ -606,20 +596,11 @@ AddNewRelationTuple(Relation pg_class_desc,
606596HeapTupleSetOid (tup ,new_rel_oid );
607597
608598/*
609- * finally insert the new tuple andfree it .
599+ * finally insert the new tuple, update the indexes, andclean up .
610600 */
611601simple_heap_insert (pg_class_desc ,tup );
612602
613- if (!IsIgnoringSystemIndexes ())
614- {
615- /*
616- * First, open the catalog indices and insert index tuples for the
617- * new relation.
618- */
619- CatalogOpenIndices (Num_pg_class_indices ,Name_pg_class_indices ,idescs );
620- CatalogIndexInsert (idescs ,Num_pg_class_indices ,pg_class_desc ,tup );
621- CatalogCloseIndices (Num_pg_class_indices ,idescs );
622- }
603+ CatalogUpdateIndexes (pg_class_desc ,tup );
623604
624605heap_freetuple (tup );
625606}
@@ -953,15 +934,8 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
953934
954935simple_heap_update (attr_rel ,& tuple -> t_self ,tuple );
955936
956- /* keep the system catalog indices current */
957- if (RelationGetForm (attr_rel )-> relhasindex )
958- {
959- Relation idescs [Num_pg_attr_indices ];
960-
961- CatalogOpenIndices (Num_pg_attr_indices ,Name_pg_attr_indices ,idescs );
962- CatalogIndexInsert (idescs ,Num_pg_attr_indices ,attr_rel ,tuple );
963- CatalogCloseIndices (Num_pg_attr_indices ,idescs );
964- }
937+ /* keep the system catalog indexes current */
938+ CatalogUpdateIndexes (attr_rel ,tuple );
965939
966940/*
967941 * Because updating the pg_attribute row will trigger a relcache flush
@@ -1087,15 +1061,8 @@ RemoveAttrDefaultById(Oid attrdefId)
10871061
10881062simple_heap_update (attr_rel ,& tuple -> t_self ,tuple );
10891063
1090- /* keep the system catalog indices current */
1091- if (RelationGetForm (attr_rel )-> relhasindex )
1092- {
1093- Relation idescs [Num_pg_attr_indices ];
1094-
1095- CatalogOpenIndices (Num_pg_attr_indices ,Name_pg_attr_indices ,idescs );
1096- CatalogIndexInsert (idescs ,Num_pg_attr_indices ,attr_rel ,tuple );
1097- CatalogCloseIndices (Num_pg_attr_indices ,idescs );
1098- }
1064+ /* keep the system catalog indexes current */
1065+ CatalogUpdateIndexes (attr_rel ,tuple );
10991066
11001067/*
11011068 * Our update of the pg_attribute row will force a relcache rebuild,
@@ -1195,12 +1162,10 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
11951162Node * expr ;
11961163char * adsrc ;
11971164Relation adrel ;
1198- Relation idescs [Num_pg_attrdef_indices ];
11991165HeapTuple tuple ;
12001166Datum values [4 ];
12011167static char nulls [4 ]= {' ' ,' ' ,' ' ,' ' };
12021168Relation attrrel ;
1203- Relation attridescs [Num_pg_attr_indices ];
12041169HeapTuple atttup ;
12051170Form_pg_attribute attStruct ;
12061171Oid attrdefOid ;
@@ -1235,10 +1200,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
12351200tuple = heap_formtuple (adrel -> rd_att ,values ,nulls );
12361201attrdefOid = simple_heap_insert (adrel ,tuple );
12371202
1238- CatalogOpenIndices (Num_pg_attrdef_indices ,Name_pg_attrdef_indices ,
1239- idescs );
1240- CatalogIndexInsert (idescs ,Num_pg_attrdef_indices ,adrel ,tuple );
1241- CatalogCloseIndices (Num_pg_attrdef_indices ,idescs );
1203+ CatalogUpdateIndexes (adrel ,tuple );
12421204
12431205defobject .classId = RelationGetRelid (adrel );
12441206defobject .objectId = attrdefOid ;
@@ -1269,11 +1231,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
12691231{
12701232attStruct -> atthasdef = true;
12711233simple_heap_update (attrrel ,& atttup -> t_self ,atttup );
1272- /* keep catalog indices current */
1273- CatalogOpenIndices (Num_pg_attr_indices ,Name_pg_attr_indices ,
1274- attridescs );
1275- CatalogIndexInsert (attridescs ,Num_pg_attr_indices ,attrrel ,atttup );
1276- CatalogCloseIndices (Num_pg_attr_indices ,attridescs );
1234+ /* keep catalog indexes current */
1235+ CatalogUpdateIndexes (attrrel ,atttup );
12771236}
12781237heap_close (attrrel ,RowExclusiveLock );
12791238heap_freetuple (atttup );
@@ -1655,7 +1614,6 @@ SetRelationNumChecks(Relation rel, int numchecks)
16551614Relation relrel ;
16561615HeapTuple reltup ;
16571616Form_pg_class relStruct ;
1658- Relation relidescs [Num_pg_class_indices ];
16591617
16601618relrel = heap_openr (RelationRelationName ,RowExclusiveLock );
16611619reltup = SearchSysCacheCopy (RELOID ,
@@ -1672,11 +1630,8 @@ SetRelationNumChecks(Relation rel, int numchecks)
16721630
16731631simple_heap_update (relrel ,& reltup -> t_self ,reltup );
16741632
1675- /* keep catalog indices current */
1676- CatalogOpenIndices (Num_pg_class_indices ,Name_pg_class_indices ,
1677- relidescs );
1678- CatalogIndexInsert (relidescs ,Num_pg_class_indices ,relrel ,reltup );
1679- CatalogCloseIndices (Num_pg_class_indices ,relidescs );
1633+ /* keep catalog indexes current */
1634+ CatalogUpdateIndexes (relrel ,reltup );
16801635}
16811636else
16821637{
@@ -1866,9 +1821,9 @@ RemoveStatistics(Relation rel)
18661821
18671822/*
18681823 * RelationTruncateIndexes - truncate all
1869- *indices associated with the heap relation to zero tuples.
1824+ *indexes associated with the heap relation to zero tuples.
18701825 *
1871- * The routine will truncate and then reconstruct theindices on
1826+ * The routine will truncate and then reconstruct theindexes on
18721827 * the relation specified by the heapId parameter.
18731828 */
18741829static void