8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.136 2001/01/23 04:32:21 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.137 2001/01/24 00:06:07 tgl Exp $
12
12
*
13
13
*
14
14
* INTERFACE ROUTINES
62
62
static Oid GetHeapRelationOid (char * heapRelationName , char * indexRelationName ,
63
63
bool istemp );
64
64
static TupleDesc BuildFuncTupleDesc (Oid funcOid );
65
- static TupleDesc ConstructTupleDescriptor (Oid heapoid , Relation heapRelation ,
65
+ static TupleDesc ConstructTupleDescriptor (Relation heapRelation ,
66
66
int numatts , AttrNumber * attNums );
67
67
static void ConstructIndexReldesc (Relation indexRelation , Oid amoid );
68
68
static Oid UpdateRelationRelation (Relation indexRelation , char * temp_relname );
@@ -166,7 +166,7 @@ BuildFuncTupleDesc(Oid funcOid)
166
166
Oid retType ;
167
167
168
168
/*
169
- * Allocate and zero a tuple descriptor.
169
+ * Allocate and zero a tuple descriptor for a one-column tuple .
170
170
*/
171
171
funcTupDesc = CreateTemplateTupleDesc (1 );
172
172
funcTupDesc -> attrs [0 ] = (Form_pg_attribute ) palloc (ATTRIBUTE_TUPLE_SIZE );
@@ -208,7 +208,7 @@ BuildFuncTupleDesc(Oid funcOid)
208
208
funcTupDesc -> attrs [0 ]-> attbyval = ((Form_pg_type ) GETSTRUCT (tuple ))-> typbyval ;
209
209
funcTupDesc -> attrs [0 ]-> attcacheoff = -1 ;
210
210
funcTupDesc -> attrs [0 ]-> atttypmod = -1 ;
211
- funcTupDesc -> attrs [0 ]-> attstorage = 'p' ;
211
+ funcTupDesc -> attrs [0 ]-> attstorage = (( Form_pg_type ) GETSTRUCT ( tuple )) -> typstorage ;
212
212
funcTupDesc -> attrs [0 ]-> attalign = ((Form_pg_type ) GETSTRUCT (tuple ))-> typalign ;
213
213
214
214
ReleaseSysCache (tuple );
@@ -223,8 +223,7 @@ BuildFuncTupleDesc(Oid funcOid)
223
223
* ----------------------------------------------------------------
224
224
*/
225
225
static TupleDesc
226
- ConstructTupleDescriptor (Oid heapoid ,
227
- Relation heapRelation ,
226
+ ConstructTupleDescriptor (Relation heapRelation ,
228
227
int numatts ,
229
228
AttrNumber * attNums )
230
229
{
@@ -253,25 +252,16 @@ ConstructTupleDescriptor(Oid heapoid,
253
252
{
254
253
AttrNumber atnum ; /* attributeNumber[attributeOffset] */
255
254
AttrNumber atind ;
256
- char * from ; /* used to simplify memcpy below */
257
- char * to ; /* used to simplify memcpy below */
255
+ Form_pg_attribute from ;
256
+ Form_pg_attribute to ;
258
257
259
258
/* ----------------
260
- * get the attribute number and make sure it's valid
259
+ * get the attribute number and make sure it's valid;
260
+ * determine which attribute descriptor to copy
261
261
* ----------------
262
262
*/
263
263
atnum = attNums [i ];
264
- if (atnum > natts )
265
- elog (ERROR , "Cannot create index: attribute %d does not exist" ,
266
- atnum );
267
264
268
- indexTupDesc -> attrs [i ] =
269
- (Form_pg_attribute ) palloc (ATTRIBUTE_TUPLE_SIZE );
270
-
271
- /* ----------------
272
- * determine which tuple descriptor to copy
273
- * ----------------
274
- */
275
265
if (!AttrNumberIsForUserDefinedAttr (atnum ))
276
266
{
277
267
/* ----------------
@@ -285,44 +275,47 @@ ConstructTupleDescriptor(Oid heapoid,
285
275
elog (ERROR , "Cannot create index on system attribute: attribute number out of range (%d)" , atnum );
286
276
atind = (- atnum ) - 1 ;
287
277
288
- from = ( char * ) ( & sysatts [atind ]) ;
278
+ from = & sysatts [atind ];
289
279
}
290
280
else
291
281
{
292
282
/* ----------------
293
283
* here we are indexing on a normal attribute (1...n)
294
284
* ----------------
295
285
*/
286
+ if (atnum > natts )
287
+ elog (ERROR , "Cannot create index: attribute %d does not exist" ,
288
+ atnum );
296
289
atind = AttrNumberGetAttrOffset (atnum );
297
290
298
- from = ( char * ) ( heapTupDesc -> attrs [atind ]) ;
291
+ from = heapTupDesc -> attrs [atind ];
299
292
}
300
293
301
294
/* ----------------
302
295
* now that we've determined the "from", let's copy
303
296
* the tuple desc data...
304
297
* ----------------
305
298
*/
306
- to = (char * ) (indexTupDesc -> attrs [i ]);
299
+ indexTupDesc -> attrs [i ] = to =
300
+ (Form_pg_attribute ) palloc (ATTRIBUTE_TUPLE_SIZE );
307
301
memcpy (to , from , ATTRIBUTE_TUPLE_SIZE );
308
302
309
303
/*
310
304
* Fix the stuff that should not be the same as the underlying attr
311
305
*/
312
- (( Form_pg_attribute ) to ) -> attnum = i + 1 ;
306
+ to -> attnum = i + 1 ;
313
307
314
- (( Form_pg_attribute ) to ) -> attdispersion = 0.0 ;
315
- (( Form_pg_attribute ) to ) -> attnotnull = false;
316
- (( Form_pg_attribute ) to ) -> atthasdef = false;
317
- (( Form_pg_attribute ) to ) -> attcacheoff = -1 ;
308
+ to -> attdispersion = 0.0 ;
309
+ to -> attnotnull = false;
310
+ to -> atthasdef = false;
311
+ to -> attcacheoff = -1 ;
318
312
319
- /* ----------------
320
- * now we have to drop in the proper relation descriptor
321
- * into the copied tuple form's attrelid and we should be
322
- * all set.
323
- * ----------------
313
+ /*
314
+ * We do not yet have the correct relation OID for the index,
315
+ * so just set it invalid for now. InitializeAttributeOids()
316
+ * will fix it later.
324
317
*/
325
- (( Form_pg_attribute ) to ) -> attrelid = heapoid ;
318
+ to -> attrelid = InvalidOid ;
326
319
}
327
320
328
321
return indexTupDesc ;
@@ -916,8 +909,7 @@ index_create(char *heapRelationName,
916
909
if (OidIsValid (indexInfo -> ii_FuncOid ))
917
910
indexTupDesc = BuildFuncTupleDesc (indexInfo -> ii_FuncOid );
918
911
else
919
- indexTupDesc = ConstructTupleDescriptor (heapoid ,
920
- heapRelation ,
912
+ indexTupDesc = ConstructTupleDescriptor (heapRelation ,
921
913
indexInfo -> ii_NumKeyAttrs ,
922
914
indexInfo -> ii_KeyAttrNumbers );
923
915
0 commit comments