77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.83 1999/12/28 13:40:49 wieck Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.84 1999/12/30 05:05:11 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -378,31 +378,27 @@ static Relation
378378AllocateRelationDesc (Relation relation ,u_int natts ,
379379Form_pg_class relp )
380380{
381- Size len ;
382381Form_pg_class relationForm ;
383382
384383/* ----------------
385384 *allocate space for the relation tuple form
386385 * ----------------
387386 */
388- relationForm = (Form_pg_class )
389- palloc ((Size ) (sizeof (FormData_pg_class )));
387+ relationForm = (Form_pg_class )palloc (sizeof (FormData_pg_class ));
390388
391- memmove ((char * )relationForm , (char * )relp ,CLASS_TUPLE_SIZE );
389+ memcpy ((char * )relationForm , (char * )relp ,CLASS_TUPLE_SIZE );
392390
393391/* ----------------
394392 *allocate space for new relation descriptor, if needed
395393 */
396- len = sizeof (RelationData );
397-
398394if (relation == NULL )
399- relation = (Relation )palloc (len );
395+ relation = (Relation )palloc (sizeof ( RelationData ) );
400396
401397/* ----------------
402398 *clear new reldesc
403399 * ----------------
404400 */
405- MemSet ((char * )relation ,0 ,len );
401+ MemSet ((char * )relation ,0 ,sizeof ( RelationData ) );
406402
407403/* make sure relation is marked as having no open file yet */
408404relation -> rd_fd = -1 ;
@@ -745,14 +741,10 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
745741u_int natts ;
746742Oid relid ;
747743Oid relam ;
744+ HeapTuple pg_class_tuple ;
748745Form_pg_class relp ;
749-
750746MemoryContext oldcxt ;
751747
752- HeapTuple pg_class_tuple ;
753-
754- oldcxt = MemoryContextSwitchTo ((MemoryContext )CacheCxt );
755-
756748/* ----------------
757749 *find the tuple in pg_class corresponding to the given relation id
758750 * ----------------
@@ -764,11 +756,7 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
764756 * ----------------
765757 */
766758if (!HeapTupleIsValid (pg_class_tuple ))
767- {
768- MemoryContextSwitchTo (oldcxt );
769-
770759return NULL ;
771- }
772760
773761/* ----------------
774762 *get information from the pg_class_tuple
@@ -781,8 +769,10 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
781769/* ----------------
782770 *allocate storage for the relation descriptor,
783771 *initialize relation->rd_rel and get the access method id.
772+ *The storage is allocated in memory context CacheCxt.
784773 * ----------------
785774 */
775+ oldcxt = MemoryContextSwitchTo ((MemoryContext )CacheCxt );
786776relation = AllocateRelationDesc (oldrelation ,natts ,relp );
787777relam = relation -> rd_rel -> relam ;
788778
@@ -866,15 +856,15 @@ RelationBuildDesc(RelationBuildDescInfo buildinfo,
866856 */
867857RelationCacheInsert (relation );
868858
859+ MemoryContextSwitchTo (oldcxt );
860+
869861/* -------------------
870862 *free the memory allocated for pg_class_tuple
871863 *and for lock data pointed to by pg_class_tuple
872864 * -------------------
873865 */
874866heap_freetuple (pg_class_tuple );
875867
876- MemoryContextSwitchTo (oldcxt );
877-
878868return relation ;
879869}
880870
@@ -1764,7 +1754,6 @@ AttrDefaultFetch(Relation relation)
17641754ndef - found ,RelationGetRelationName (relation ));
17651755
17661756index_endscan (sd );
1767- pfree (sd );
17681757index_close (irel );
17691758heap_close (adrel ,AccessShareLock );
17701759}
@@ -1837,7 +1826,6 @@ RelCheckFetch(Relation relation)
18371826ncheck - found ,RelationGetRelationName (relation ));
18381827
18391828index_endscan (sd );
1840- pfree (sd );
18411829index_close (irel );
18421830heap_close (rcrel ,AccessShareLock );
18431831}