Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 997ee51

Browse files
committedJan 24, 2001
Make functional index copy attstorage from the column data type, rather
than forcing 'plain'. This probably does not matter right now, but I think it needs to be consistent with the regular (not-functional) index case, where attstorage is copied from the underlying table. Clean up some other dead and infelicitous code too.
1 parent c654c69 commit 997ee51

File tree

1 file changed

+27
-35
lines changed

1 file changed

+27
-35
lines changed
 

‎src/backend/catalog/index.c

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* 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 $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -62,7 +62,7 @@
6262
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName,
6363
bool istemp);
6464
static TupleDesc BuildFuncTupleDesc(Oid funcOid);
65-
static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation,
65+
static TupleDesc ConstructTupleDescriptor(Relation heapRelation,
6666
int numatts, AttrNumber *attNums);
6767
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
6868
static Oid UpdateRelationRelation(Relation indexRelation, char *temp_relname);
@@ -166,7 +166,7 @@ BuildFuncTupleDesc(Oid funcOid)
166166
Oid retType;
167167

168168
/*
169-
* Allocate and zero a tuple descriptor.
169+
* Allocate and zero a tuple descriptor for a one-column tuple.
170170
*/
171171
funcTupDesc = CreateTemplateTupleDesc(1);
172172
funcTupDesc->attrs[0] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
@@ -208,7 +208,7 @@ BuildFuncTupleDesc(Oid funcOid)
208208
funcTupDesc->attrs[0]->attbyval = ((Form_pg_type) GETSTRUCT(tuple))->typbyval;
209209
funcTupDesc->attrs[0]->attcacheoff = -1;
210210
funcTupDesc->attrs[0]->atttypmod = -1;
211-
funcTupDesc->attrs[0]->attstorage = 'p';
211+
funcTupDesc->attrs[0]->attstorage = ((Form_pg_type) GETSTRUCT(tuple))->typstorage;
212212
funcTupDesc->attrs[0]->attalign = ((Form_pg_type) GETSTRUCT(tuple))->typalign;
213213

214214
ReleaseSysCache(tuple);
@@ -223,8 +223,7 @@ BuildFuncTupleDesc(Oid funcOid)
223223
* ----------------------------------------------------------------
224224
*/
225225
static TupleDesc
226-
ConstructTupleDescriptor(Oid heapoid,
227-
Relation heapRelation,
226+
ConstructTupleDescriptor(Relation heapRelation,
228227
int numatts,
229228
AttrNumber *attNums)
230229
{
@@ -253,25 +252,16 @@ ConstructTupleDescriptor(Oid heapoid,
253252
{
254253
AttrNumber atnum; /* attributeNumber[attributeOffset] */
255254
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;
258257

259258
/* ----------------
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
261261
* ----------------
262262
*/
263263
atnum = attNums[i];
264-
if (atnum > natts)
265-
elog(ERROR, "Cannot create index: attribute %d does not exist",
266-
atnum);
267264

268-
indexTupDesc->attrs[i] =
269-
(Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
270-
271-
/* ----------------
272-
* determine which tuple descriptor to copy
273-
* ----------------
274-
*/
275265
if (!AttrNumberIsForUserDefinedAttr(atnum))
276266
{
277267
/* ----------------
@@ -285,44 +275,47 @@ ConstructTupleDescriptor(Oid heapoid,
285275
elog(ERROR, "Cannot create index on system attribute: attribute number out of range (%d)", atnum);
286276
atind = (-atnum) - 1;
287277

288-
from = (char *) (&sysatts[atind]);
278+
from = &sysatts[atind];
289279
}
290280
else
291281
{
292282
/* ----------------
293283
* here we are indexing on a normal attribute (1...n)
294284
* ----------------
295285
*/
286+
if (atnum > natts)
287+
elog(ERROR, "Cannot create index: attribute %d does not exist",
288+
atnum);
296289
atind = AttrNumberGetAttrOffset(atnum);
297290

298-
from = (char *) (heapTupDesc->attrs[atind]);
291+
from = heapTupDesc->attrs[atind];
299292
}
300293

301294
/* ----------------
302295
* now that we've determined the "from", let's copy
303296
* the tuple desc data...
304297
* ----------------
305298
*/
306-
to = (char *) (indexTupDesc->attrs[i]);
299+
indexTupDesc->attrs[i] = to =
300+
(Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
307301
memcpy(to, from, ATTRIBUTE_TUPLE_SIZE);
308302

309303
/*
310304
* Fix the stuff that should not be the same as the underlying attr
311305
*/
312-
((Form_pg_attribute) to)->attnum = i + 1;
306+
to->attnum = i + 1;
313307

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;
318312

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.
324317
*/
325-
((Form_pg_attribute) to)->attrelid = heapoid;
318+
to->attrelid = InvalidOid;
326319
}
327320

328321
return indexTupDesc;
@@ -916,8 +909,7 @@ index_create(char *heapRelationName,
916909
if (OidIsValid(indexInfo->ii_FuncOid))
917910
indexTupDesc = BuildFuncTupleDesc(indexInfo->ii_FuncOid);
918911
else
919-
indexTupDesc = ConstructTupleDescriptor(heapoid,
920-
heapRelation,
912+
indexTupDesc = ConstructTupleDescriptor(heapRelation,
921913
indexInfo->ii_NumKeyAttrs,
922914
indexInfo->ii_KeyAttrNumbers);
923915

0 commit comments

Comments
 (0)
Failed to load comments.