88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.95 2000/04/12 17:15:54 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/relcache.c,v 1.96 2000/05/21 02:28:55 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -245,6 +245,9 @@ static bool criticalRelcacheBuild = false;
245245 *this is used by RelationBuildDesc to find a pg_class
246246 *tuple matching either a relation name or a relation id
247247 *as specified in buildinfo.
248+ *
249+ *NB: the returned tuple has been copied into palloc'd storage
250+ *and must eventually be freed with heap_freetuple.
248251 * --------------------------------
249252 */
250253static HeapTuple
@@ -356,6 +359,8 @@ scan_pg_rel_ind(RelationBuildDescInfo buildinfo)
356359
357360heap_close (pg_class_desc ,AccessShareLock );
358361
362+ /* The xxxIndexScan routines will have returned a palloc'd tuple. */
363+
359364return return_tuple ;
360365}
361366
@@ -519,9 +524,9 @@ build_tupdesc_seq(RelationBuildDescInfo buildinfo,
519524relation -> rd_att -> attrs [attp -> attnum - 1 ]=
520525(Form_pg_attribute )palloc (ATTRIBUTE_TUPLE_SIZE );
521526
522- memmove ((char * ) (relation -> rd_att -> attrs [attp -> attnum - 1 ]),
523- (char * )attp ,
524- ATTRIBUTE_TUPLE_SIZE );
527+ memcpy ((char * ) (relation -> rd_att -> attrs [attp -> attnum - 1 ]),
528+ (char * )attp ,
529+ ATTRIBUTE_TUPLE_SIZE );
525530need -- ;
526531/* Update if this attribute have a constraint */
527532if (attp -> attnotnull )
@@ -571,26 +576,22 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
571576int ndef = 0 ;
572577int i ;
573578
574- #ifdef _DROP_COLUMN_HACK__
575- bool columnDropped ;
576-
577- #endif /* _DROP_COLUMN_HACK__ */
578-
579579constr -> has_not_null = false;
580580
581581attrel = heap_openr (AttributeRelationName ,AccessShareLock );
582582
583583for (i = 1 ;i <=relation -> rd_rel -> relnatts ;i ++ )
584584{
585585#ifdef _DROP_COLUMN_HACK__
586- columnDropped = false;
586+ bool columnDropped = false;
587587#endif /* _DROP_COLUMN_HACK__ */
588+
588589atttup = (HeapTuple )AttributeRelidNumIndexScan (attrel ,
589590RelationGetRelid (relation ),i );
590591
591592if (!HeapTupleIsValid (atttup ))
592- #ifdef _DROP_COLUMN_HACK__
593593{
594+ #ifdef _DROP_COLUMN_HACK__
594595atttup = (HeapTuple )AttributeRelidNumIndexScan (attrel ,
595596RelationGetRelid (relation ),DROPPED_COLUMN_INDEX (i ));
596597if (!HeapTupleIsValid (atttup ))
@@ -599,21 +600,24 @@ build_tupdesc_ind(RelationBuildDescInfo buildinfo,
599600RelationGetRelationName (relation ));
600601#ifdef _DROP_COLUMN_HACK__
601602columnDropped = true;
602- }
603603#endif /* _DROP_COLUMN_HACK__ */
604- attp = ( Form_pg_attribute ) GETSTRUCT ( atttup );
604+ }
605605
606- relation -> rd_att -> attrs [i - 1 ]=
606+ relation -> rd_att -> attrs [i - 1 ]= attp =
607607(Form_pg_attribute )palloc (ATTRIBUTE_TUPLE_SIZE );
608608
609- memmove ((char * ) (relation -> rd_att -> attrs [i - 1 ]),
610- (char * )attp ,
611- ATTRIBUTE_TUPLE_SIZE );
609+ memcpy ((char * )attp ,
610+ (char * ) (Form_pg_attribute )GETSTRUCT (atttup ),
611+ ATTRIBUTE_TUPLE_SIZE );
612+
613+ /* don't forget to free the tuple returned from xxxIndexScan */
614+ heap_freetuple (atttup );
612615
613616#ifdef _DROP_COLUMN_HACK__
614617if (columnDropped )
615618continue ;
616619#endif /* _DROP_COLUMN_HACK__ */
620+
617621/* Update if this attribute have a constraint */
618622if (attp -> attnotnull )
619623constr -> has_not_null = true;
@@ -1117,12 +1121,9 @@ formrdesc(char *relationName,
11171121for (i = 0 ;i < natts ;i ++ )
11181122{
11191123relation -> rd_att -> attrs [i ]= (Form_pg_attribute )palloc (ATTRIBUTE_TUPLE_SIZE );
1120-
1121- MemSet (( char * )relation -> rd_att -> attrs [i ], 0 ,
1124+ memcpy (( char * ) relation -> rd_att -> attrs [ i ],
1125+ ( char * )& att [i ],
11221126ATTRIBUTE_TUPLE_SIZE );
1123- memmove ((char * )relation -> rd_att -> attrs [i ],
1124- (char * )& att [i ],
1125- ATTRIBUTE_TUPLE_SIZE );
11261127}
11271128
11281129/* ----------------