8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.217 2002/08/05 02:30:50 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.218 2002/08/05 03:29:16 tgl Exp $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
@@ -423,23 +423,17 @@ AddNewAttributeTuples(Oid new_rel_oid,
423
423
int i ;
424
424
HeapTuple tup ;
425
425
Relation rel ;
426
- bool hasindex ;
427
- Relation idescs [Num_pg_attr_indices ];
426
+ CatalogIndexState indstate ;
428
427
int natts = tupdesc -> natts ;
429
428
ObjectAddress myself ,
430
429
referenced ;
431
430
432
431
/*
433
- * open pg_attribute
432
+ * open pg_attribute and its indexes.
434
433
*/
435
434
rel = heap_openr (AttributeRelationName , RowExclusiveLock );
436
435
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 );
443
437
444
438
/*
445
439
* First we add the user attributes. This is also a convenient place
@@ -461,8 +455,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
461
455
462
456
simple_heap_insert (rel , tup );
463
457
464
- if (hasindex )
465
- CatalogIndexInsert (idescs , Num_pg_attr_indices , rel , tup );
458
+ CatalogIndexInsert (indstate , tup );
466
459
467
460
heap_freetuple (tup );
468
461
@@ -509,8 +502,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
509
502
510
503
simple_heap_insert (rel , tup );
511
504
512
- if (hasindex )
513
- CatalogIndexInsert (idescs , Num_pg_attr_indices , rel , tup );
505
+ CatalogIndexInsert (indstate , tup );
514
506
515
507
heap_freetuple (tup );
516
508
}
@@ -521,8 +513,7 @@ AddNewAttributeTuples(Oid new_rel_oid,
521
513
/*
522
514
* clean up
523
515
*/
524
- if (hasindex )
525
- CatalogCloseIndices (Num_pg_attr_indices , idescs );
516
+ CatalogCloseIndexes (indstate );
526
517
527
518
heap_close (rel , RowExclusiveLock );
528
519
}
@@ -543,7 +534,6 @@ AddNewRelationTuple(Relation pg_class_desc,
543
534
{
544
535
Form_pg_class new_rel_reltup ;
545
536
HeapTuple tup ;
546
- Relation idescs [Num_pg_class_indices ];
547
537
548
538
/*
549
539
* first we update some of the information in our uncataloged
@@ -606,20 +596,11 @@ AddNewRelationTuple(Relation pg_class_desc,
606
596
HeapTupleSetOid (tup , new_rel_oid );
607
597
608
598
/*
609
- * finally insert the new tuple and free it .
599
+ * finally insert the new tuple, update the indexes, and clean up .
610
600
*/
611
601
simple_heap_insert (pg_class_desc , tup );
612
602
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 );
623
604
624
605
heap_freetuple (tup );
625
606
}
@@ -953,15 +934,8 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
953
934
954
935
simple_heap_update (attr_rel , & tuple -> t_self , tuple );
955
936
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 );
965
939
966
940
/*
967
941
* Because updating the pg_attribute row will trigger a relcache flush
@@ -1087,15 +1061,8 @@ RemoveAttrDefaultById(Oid attrdefId)
1087
1061
1088
1062
simple_heap_update (attr_rel , & tuple -> t_self , tuple );
1089
1063
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 );
1099
1066
1100
1067
/*
1101
1068
* Our update of the pg_attribute row will force a relcache rebuild,
@@ -1195,12 +1162,10 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
1195
1162
Node * expr ;
1196
1163
char * adsrc ;
1197
1164
Relation adrel ;
1198
- Relation idescs [Num_pg_attrdef_indices ];
1199
1165
HeapTuple tuple ;
1200
1166
Datum values [4 ];
1201
1167
static char nulls [4 ] = {' ' , ' ' , ' ' , ' ' };
1202
1168
Relation attrrel ;
1203
- Relation attridescs [Num_pg_attr_indices ];
1204
1169
HeapTuple atttup ;
1205
1170
Form_pg_attribute attStruct ;
1206
1171
Oid attrdefOid ;
@@ -1235,10 +1200,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
1235
1200
tuple = heap_formtuple (adrel -> rd_att , values , nulls );
1236
1201
attrdefOid = simple_heap_insert (adrel , tuple );
1237
1202
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 );
1242
1204
1243
1205
defobject .classId = RelationGetRelid (adrel );
1244
1206
defobject .objectId = attrdefOid ;
@@ -1269,11 +1231,8 @@ StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin)
1269
1231
{
1270
1232
attStruct -> atthasdef = true;
1271
1233
simple_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 );
1277
1236
}
1278
1237
heap_close (attrrel , RowExclusiveLock );
1279
1238
heap_freetuple (atttup );
@@ -1655,7 +1614,6 @@ SetRelationNumChecks(Relation rel, int numchecks)
1655
1614
Relation relrel ;
1656
1615
HeapTuple reltup ;
1657
1616
Form_pg_class relStruct ;
1658
- Relation relidescs [Num_pg_class_indices ];
1659
1617
1660
1618
relrel = heap_openr (RelationRelationName , RowExclusiveLock );
1661
1619
reltup = SearchSysCacheCopy (RELOID ,
@@ -1672,11 +1630,8 @@ SetRelationNumChecks(Relation rel, int numchecks)
1672
1630
1673
1631
simple_heap_update (relrel , & reltup -> t_self , reltup );
1674
1632
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 );
1680
1635
}
1681
1636
else
1682
1637
{
@@ -1866,9 +1821,9 @@ RemoveStatistics(Relation rel)
1866
1821
1867
1822
/*
1868
1823
* RelationTruncateIndexes - truncate all
1869
- * indices associated with the heap relation to zero tuples.
1824
+ * indexes associated with the heap relation to zero tuples.
1870
1825
*
1871
- * The routine will truncate and then reconstruct the indices on
1826
+ * The routine will truncate and then reconstruct the indexes on
1872
1827
* the relation specified by the heapId parameter.
1873
1828
*/
1874
1829
static void
0 commit comments