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.
This commit is contained in:
Tom Lane 2001-01-24 00:06:07 +00:00
parent c654c69c05
commit 997ee51631

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.136 2001/01/23 04:32:21 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.137 2001/01/24 00:06:07 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
@ -62,7 +62,7 @@
static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName, static Oid GetHeapRelationOid(char *heapRelationName, char *indexRelationName,
bool istemp); bool istemp);
static TupleDesc BuildFuncTupleDesc(Oid funcOid); static TupleDesc BuildFuncTupleDesc(Oid funcOid);
static TupleDesc ConstructTupleDescriptor(Oid heapoid, Relation heapRelation, static TupleDesc ConstructTupleDescriptor(Relation heapRelation,
int numatts, AttrNumber *attNums); int numatts, AttrNumber *attNums);
static void ConstructIndexReldesc(Relation indexRelation, Oid amoid); static void ConstructIndexReldesc(Relation indexRelation, Oid amoid);
static Oid UpdateRelationRelation(Relation indexRelation, char *temp_relname); static Oid UpdateRelationRelation(Relation indexRelation, char *temp_relname);
@ -166,7 +166,7 @@ BuildFuncTupleDesc(Oid funcOid)
Oid retType; Oid retType;
/* /*
* Allocate and zero a tuple descriptor. * Allocate and zero a tuple descriptor for a one-column tuple.
*/ */
funcTupDesc = CreateTemplateTupleDesc(1); funcTupDesc = CreateTemplateTupleDesc(1);
funcTupDesc->attrs[0] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE); funcTupDesc->attrs[0] = (Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
@ -208,7 +208,7 @@ BuildFuncTupleDesc(Oid funcOid)
funcTupDesc->attrs[0]->attbyval = ((Form_pg_type) GETSTRUCT(tuple))->typbyval; funcTupDesc->attrs[0]->attbyval = ((Form_pg_type) GETSTRUCT(tuple))->typbyval;
funcTupDesc->attrs[0]->attcacheoff = -1; funcTupDesc->attrs[0]->attcacheoff = -1;
funcTupDesc->attrs[0]->atttypmod = -1; funcTupDesc->attrs[0]->atttypmod = -1;
funcTupDesc->attrs[0]->attstorage = 'p'; funcTupDesc->attrs[0]->attstorage = ((Form_pg_type) GETSTRUCT(tuple))->typstorage;
funcTupDesc->attrs[0]->attalign = ((Form_pg_type) GETSTRUCT(tuple))->typalign; funcTupDesc->attrs[0]->attalign = ((Form_pg_type) GETSTRUCT(tuple))->typalign;
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
@ -223,8 +223,7 @@ BuildFuncTupleDesc(Oid funcOid)
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
static TupleDesc static TupleDesc
ConstructTupleDescriptor(Oid heapoid, ConstructTupleDescriptor(Relation heapRelation,
Relation heapRelation,
int numatts, int numatts,
AttrNumber *attNums) AttrNumber *attNums)
{ {
@ -253,25 +252,16 @@ ConstructTupleDescriptor(Oid heapoid,
{ {
AttrNumber atnum; /* attributeNumber[attributeOffset] */ AttrNumber atnum; /* attributeNumber[attributeOffset] */
AttrNumber atind; AttrNumber atind;
char *from; /* used to simplify memcpy below */ Form_pg_attribute from;
char *to; /* used to simplify memcpy below */ Form_pg_attribute to;
/* ---------------- /* ----------------
* get the attribute number and make sure it's valid * get the attribute number and make sure it's valid;
* determine which attribute descriptor to copy
* ---------------- * ----------------
*/ */
atnum = attNums[i]; atnum = attNums[i];
if (atnum > natts)
elog(ERROR, "Cannot create index: attribute %d does not exist",
atnum);
indexTupDesc->attrs[i] =
(Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
/* ----------------
* determine which tuple descriptor to copy
* ----------------
*/
if (!AttrNumberIsForUserDefinedAttr(atnum)) if (!AttrNumberIsForUserDefinedAttr(atnum))
{ {
/* ---------------- /* ----------------
@ -285,7 +275,7 @@ ConstructTupleDescriptor(Oid heapoid,
elog(ERROR, "Cannot create index on system attribute: attribute number out of range (%d)", atnum); elog(ERROR, "Cannot create index on system attribute: attribute number out of range (%d)", atnum);
atind = (-atnum) - 1; atind = (-atnum) - 1;
from = (char *) (&sysatts[atind]); from = &sysatts[atind];
} }
else else
{ {
@ -293,9 +283,12 @@ ConstructTupleDescriptor(Oid heapoid,
* here we are indexing on a normal attribute (1...n) * here we are indexing on a normal attribute (1...n)
* ---------------- * ----------------
*/ */
if (atnum > natts)
elog(ERROR, "Cannot create index: attribute %d does not exist",
atnum);
atind = AttrNumberGetAttrOffset(atnum); atind = AttrNumberGetAttrOffset(atnum);
from = (char *) (heapTupDesc->attrs[atind]); from = heapTupDesc->attrs[atind];
} }
/* ---------------- /* ----------------
@ -303,26 +296,26 @@ ConstructTupleDescriptor(Oid heapoid,
* the tuple desc data... * the tuple desc data...
* ---------------- * ----------------
*/ */
to = (char *) (indexTupDesc->attrs[i]); indexTupDesc->attrs[i] = to =
(Form_pg_attribute) palloc(ATTRIBUTE_TUPLE_SIZE);
memcpy(to, from, ATTRIBUTE_TUPLE_SIZE); memcpy(to, from, ATTRIBUTE_TUPLE_SIZE);
/* /*
* Fix the stuff that should not be the same as the underlying attr * Fix the stuff that should not be the same as the underlying attr
*/ */
((Form_pg_attribute) to)->attnum = i + 1; to->attnum = i + 1;
((Form_pg_attribute) to)->attdispersion = 0.0; to->attdispersion = 0.0;
((Form_pg_attribute) to)->attnotnull = false; to->attnotnull = false;
((Form_pg_attribute) to)->atthasdef = false; to->atthasdef = false;
((Form_pg_attribute) to)->attcacheoff = -1; to->attcacheoff = -1;
/* ---------------- /*
* now we have to drop in the proper relation descriptor * We do not yet have the correct relation OID for the index,
* into the copied tuple form's attrelid and we should be * so just set it invalid for now. InitializeAttributeOids()
* all set. * will fix it later.
* ----------------
*/ */
((Form_pg_attribute) to)->attrelid = heapoid; to->attrelid = InvalidOid;
} }
return indexTupDesc; return indexTupDesc;
@ -916,8 +909,7 @@ index_create(char *heapRelationName,
if (OidIsValid(indexInfo->ii_FuncOid)) if (OidIsValid(indexInfo->ii_FuncOid))
indexTupDesc = BuildFuncTupleDesc(indexInfo->ii_FuncOid); indexTupDesc = BuildFuncTupleDesc(indexInfo->ii_FuncOid);
else else
indexTupDesc = ConstructTupleDescriptor(heapoid, indexTupDesc = ConstructTupleDescriptor(heapRelation,
heapRelation,
indexInfo->ii_NumKeyAttrs, indexInfo->ii_NumKeyAttrs,
indexInfo->ii_KeyAttrNumbers); indexInfo->ii_KeyAttrNumbers);