1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-17 01:02:17 +03:00

Change tupledesc->attrs[n] to TupleDescAttr(tupledesc, n).

This is a mechanical change in preparation for a later commit that
will change the layout of TupleDesc.  Introducing a macro to abstract
the details of where attributes are stored will allow us to change
that in separate step and revise it in future.

Author: Thomas Munro, editorialized by Andres Freund
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com
This commit is contained in:
Andres Freund
2017-08-20 11:19:07 -07:00
parent b1c2d76a2f
commit 2cd7084524
100 changed files with 805 additions and 626 deletions

View File

@@ -89,7 +89,6 @@ heap_compute_data_size(TupleDesc tupleDesc,
Size data_length = 0;
int i;
int numberOfAttributes = tupleDesc->natts;
Form_pg_attribute *att = tupleDesc->attrs;
for (i = 0; i < numberOfAttributes; i++)
{
@@ -100,7 +99,7 @@ heap_compute_data_size(TupleDesc tupleDesc,
continue;
val = values[i];
atti = att[i];
atti = TupleDescAttr(tupleDesc, i);
if (ATT_IS_PACKABLE(atti) &&
VARATT_CAN_MAKE_SHORT(DatumGetPointer(val)))
@@ -152,7 +151,6 @@ heap_fill_tuple(TupleDesc tupleDesc,
int bitmask;
int i;
int numberOfAttributes = tupleDesc->natts;
Form_pg_attribute *att = tupleDesc->attrs;
#ifdef USE_ASSERT_CHECKING
char *start = data;
@@ -174,6 +172,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
for (i = 0; i < numberOfAttributes; i++)
{
Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
Size data_length;
if (bit != NULL)
@@ -201,14 +200,14 @@ heap_fill_tuple(TupleDesc tupleDesc,
* an offset. This is a bit of a hack.
*/
if (att[i]->attbyval)
if (att->attbyval)
{
/* pass-by-value */
data = (char *) att_align_nominal(data, att[i]->attalign);
store_att_byval(data, values[i], att[i]->attlen);
data_length = att[i]->attlen;
data = (char *) att_align_nominal(data, att->attalign);
store_att_byval(data, values[i], att->attlen);
data_length = att->attlen;
}
else if (att[i]->attlen == -1)
else if (att->attlen == -1)
{
/* varlena */
Pointer val = DatumGetPointer(values[i]);
@@ -225,7 +224,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
ExpandedObjectHeader *eoh = DatumGetEOHP(values[i]);
data = (char *) att_align_nominal(data,
att[i]->attalign);
att->attalign);
data_length = EOH_get_flat_size(eoh);
EOH_flatten_into(eoh, data, data_length);
}
@@ -243,7 +242,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
data_length = VARSIZE_SHORT(val);
memcpy(data, val, data_length);
}
else if (VARLENA_ATT_IS_PACKABLE(att[i]) &&
else if (VARLENA_ATT_IS_PACKABLE(att) &&
VARATT_CAN_MAKE_SHORT(val))
{
/* convert to short varlena -- no alignment */
@@ -255,25 +254,25 @@ heap_fill_tuple(TupleDesc tupleDesc,
{
/* full 4-byte header varlena */
data = (char *) att_align_nominal(data,
att[i]->attalign);
att->attalign);
data_length = VARSIZE(val);
memcpy(data, val, data_length);
}
}
else if (att[i]->attlen == -2)
else if (att->attlen == -2)
{
/* cstring ... never needs alignment */
*infomask |= HEAP_HASVARWIDTH;
Assert(att[i]->attalign == 'c');
Assert(att->attalign == 'c');
data_length = strlen(DatumGetCString(values[i])) + 1;
memcpy(data, DatumGetPointer(values[i]), data_length);
}
else
{
/* fixed-length pass-by-reference */
data = (char *) att_align_nominal(data, att[i]->attalign);
Assert(att[i]->attlen > 0);
data_length = att[i]->attlen;
data = (char *) att_align_nominal(data, att->attalign);
Assert(att->attlen > 0);
data_length = att->attlen;
memcpy(data, DatumGetPointer(values[i]), data_length);
}
@@ -354,7 +353,6 @@ nocachegetattr(HeapTuple tuple,
TupleDesc tupleDesc)
{
HeapTupleHeader tup = tuple->t_data;
Form_pg_attribute *att = tupleDesc->attrs;
char *tp; /* ptr to data part of tuple */
bits8 *bp = tup->t_bits; /* ptr to null bitmap in tuple */
bool slow = false; /* do we have to walk attrs? */
@@ -404,15 +402,15 @@ nocachegetattr(HeapTuple tuple,
if (!slow)
{
Form_pg_attribute att;
/*
* If we get here, there are no nulls up to and including the target
* attribute. If we have a cached offset, we can use it.
*/
if (att[attnum]->attcacheoff >= 0)
{
return fetchatt(att[attnum],
tp + att[attnum]->attcacheoff);
}
att = TupleDescAttr(tupleDesc, attnum);
if (att->attcacheoff >= 0)
return fetchatt(att, tp + att->attcacheoff);
/*
* Otherwise, check for non-fixed-length attrs up to and including
@@ -425,7 +423,7 @@ nocachegetattr(HeapTuple tuple,
for (j = 0; j <= attnum; j++)
{
if (att[j]->attlen <= 0)
if (TupleDescAttr(tupleDesc, j)->attlen <= 0)
{
slow = true;
break;
@@ -448,29 +446,32 @@ nocachegetattr(HeapTuple tuple,
* fixed-width columns, in hope of avoiding future visits to this
* routine.
*/
att[0]->attcacheoff = 0;
TupleDescAttr(tupleDesc, 0)->attcacheoff = 0;
/* we might have set some offsets in the slow path previously */
while (j < natts && att[j]->attcacheoff > 0)
while (j < natts && TupleDescAttr(tupleDesc, j)->attcacheoff > 0)
j++;
off = att[j - 1]->attcacheoff + att[j - 1]->attlen;
off = TupleDescAttr(tupleDesc, j - 1)->attcacheoff +
TupleDescAttr(tupleDesc, j - 1)->attlen;
for (; j < natts; j++)
{
if (att[j]->attlen <= 0)
Form_pg_attribute att = TupleDescAttr(tupleDesc, j);
if (att->attlen <= 0)
break;
off = att_align_nominal(off, att[j]->attalign);
off = att_align_nominal(off, att->attalign);
att[j]->attcacheoff = off;
att->attcacheoff = off;
off += att[j]->attlen;
off += att->attlen;
}
Assert(j > attnum);
off = att[attnum]->attcacheoff;
off = TupleDescAttr(tupleDesc, attnum)->attcacheoff;
}
else
{
@@ -490,6 +491,8 @@ nocachegetattr(HeapTuple tuple,
off = 0;
for (i = 0;; i++) /* loop exit is at "break" */
{
Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
if (HeapTupleHasNulls(tuple) && att_isnull(i, bp))
{
usecache = false;
@@ -497,9 +500,9 @@ nocachegetattr(HeapTuple tuple,
}
/* If we know the next offset, we can skip the rest */
if (usecache && att[i]->attcacheoff >= 0)
off = att[i]->attcacheoff;
else if (att[i]->attlen == -1)
if (usecache && att->attcacheoff >= 0)
off = att->attcacheoff;
else if (att->attlen == -1)
{
/*
* We can only cache the offset for a varlena attribute if the
@@ -508,11 +511,11 @@ nocachegetattr(HeapTuple tuple,
* either an aligned or unaligned value.
*/
if (usecache &&
off == att_align_nominal(off, att[i]->attalign))
att[i]->attcacheoff = off;
off == att_align_nominal(off, att->attalign))
att->attcacheoff = off;
else
{
off = att_align_pointer(off, att[i]->attalign, -1,
off = att_align_pointer(off, att->attalign, -1,
tp + off);
usecache = false;
}
@@ -520,23 +523,23 @@ nocachegetattr(HeapTuple tuple,
else
{
/* not varlena, so safe to use att_align_nominal */
off = att_align_nominal(off, att[i]->attalign);
off = att_align_nominal(off, att->attalign);
if (usecache)
att[i]->attcacheoff = off;
att->attcacheoff = off;
}
if (i == attnum)
break;
off = att_addlength_pointer(off, att[i]->attlen, tp + off);
off = att_addlength_pointer(off, att->attlen, tp + off);
if (usecache && att[i]->attlen <= 0)
if (usecache && att->attlen <= 0)
usecache = false;
}
}
return fetchatt(att[attnum], tp + off);
return fetchatt(TupleDescAttr(tupleDesc, attnum), tp + off);
}
/* ----------------
@@ -935,7 +938,6 @@ heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
{
HeapTupleHeader tup = tuple->t_data;
bool hasnulls = HeapTupleHasNulls(tuple);
Form_pg_attribute *att = tupleDesc->attrs;
int tdesc_natts = tupleDesc->natts;
int natts; /* number of atts to extract */
int attnum;
@@ -959,7 +961,7 @@ heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc,
for (attnum = 0; attnum < natts; attnum++)
{
Form_pg_attribute thisatt = att[attnum];
Form_pg_attribute thisatt = TupleDescAttr(tupleDesc, attnum);
if (hasnulls && att_isnull(attnum, bp))
{
@@ -1039,7 +1041,6 @@ slot_deform_tuple(TupleTableSlot *slot, int natts)
bool *isnull = slot->tts_isnull;
HeapTupleHeader tup = tuple->t_data;
bool hasnulls = HeapTupleHasNulls(tuple);
Form_pg_attribute *att = tupleDesc->attrs;
int attnum;
char *tp; /* ptr to tuple data */
long off; /* offset in tuple data */
@@ -1068,7 +1069,7 @@ slot_deform_tuple(TupleTableSlot *slot, int natts)
for (; attnum < natts; attnum++)
{
Form_pg_attribute thisatt = att[attnum];
Form_pg_attribute thisatt = TupleDescAttr(tupleDesc, attnum);
if (hasnulls && att_isnull(attnum, bp))
{
@@ -1209,7 +1210,7 @@ slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)
* This case should not happen in normal use, but it could happen if we
* are executing a plan cached before the column was dropped.
*/
if (tupleDesc->attrs[attnum - 1]->attisdropped)
if (TupleDescAttr(tupleDesc, attnum - 1)->attisdropped)
{
*isnull = true;
return (Datum) 0;

View File

@@ -63,7 +63,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
#ifdef TOAST_INDEX_HACK
for (i = 0; i < numberOfAttributes; i++)
{
Form_pg_attribute att = tupleDescriptor->attrs[i];
Form_pg_attribute att = TupleDescAttr(tupleDescriptor, i);
untoasted_values[i] = values[i];
untoasted_free[i] = false;
@@ -209,7 +209,6 @@ nocache_index_getattr(IndexTuple tup,
int attnum,
TupleDesc tupleDesc)
{
Form_pg_attribute *att = tupleDesc->attrs;
char *tp; /* ptr to data part of tuple */
bits8 *bp = NULL; /* ptr to null bitmap in tuple */
bool slow = false; /* do we have to walk attrs? */
@@ -271,15 +270,15 @@ nocache_index_getattr(IndexTuple tup,
if (!slow)
{
Form_pg_attribute att;
/*
* If we get here, there are no nulls up to and including the target
* attribute. If we have a cached offset, we can use it.
*/
if (att[attnum]->attcacheoff >= 0)
{
return fetchatt(att[attnum],
tp + att[attnum]->attcacheoff);
}
att = TupleDescAttr(tupleDesc, attnum);
if (att->attcacheoff >= 0)
return fetchatt(att, tp + att->attcacheoff);
/*
* Otherwise, check for non-fixed-length attrs up to and including
@@ -292,7 +291,7 @@ nocache_index_getattr(IndexTuple tup,
for (j = 0; j <= attnum; j++)
{
if (att[j]->attlen <= 0)
if (TupleDescAttr(tupleDesc, j)->attlen <= 0)
{
slow = true;
break;
@@ -315,29 +314,32 @@ nocache_index_getattr(IndexTuple tup,
* fixed-width columns, in hope of avoiding future visits to this
* routine.
*/
att[0]->attcacheoff = 0;
TupleDescAttr(tupleDesc, 0)->attcacheoff = 0;
/* we might have set some offsets in the slow path previously */
while (j < natts && att[j]->attcacheoff > 0)
while (j < natts && TupleDescAttr(tupleDesc, j)->attcacheoff > 0)
j++;
off = att[j - 1]->attcacheoff + att[j - 1]->attlen;
off = TupleDescAttr(tupleDesc, j - 1)->attcacheoff +
TupleDescAttr(tupleDesc, j - 1)->attlen;
for (; j < natts; j++)
{
if (att[j]->attlen <= 0)
Form_pg_attribute att = TupleDescAttr(tupleDesc, j);
if (att->attlen <= 0)
break;
off = att_align_nominal(off, att[j]->attalign);
off = att_align_nominal(off, att->attalign);
att[j]->attcacheoff = off;
att->attcacheoff = off;
off += att[j]->attlen;
off += att->attlen;
}
Assert(j > attnum);
off = att[attnum]->attcacheoff;
off = TupleDescAttr(tupleDesc, attnum)->attcacheoff;
}
else
{
@@ -357,6 +359,8 @@ nocache_index_getattr(IndexTuple tup,
off = 0;
for (i = 0;; i++) /* loop exit is at "break" */
{
Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
if (IndexTupleHasNulls(tup) && att_isnull(i, bp))
{
usecache = false;
@@ -364,9 +368,9 @@ nocache_index_getattr(IndexTuple tup,
}
/* If we know the next offset, we can skip the rest */
if (usecache && att[i]->attcacheoff >= 0)
off = att[i]->attcacheoff;
else if (att[i]->attlen == -1)
if (usecache && att->attcacheoff >= 0)
off = att->attcacheoff;
else if (att->attlen == -1)
{
/*
* We can only cache the offset for a varlena attribute if the
@@ -375,11 +379,11 @@ nocache_index_getattr(IndexTuple tup,
* either an aligned or unaligned value.
*/
if (usecache &&
off == att_align_nominal(off, att[i]->attalign))
att[i]->attcacheoff = off;
off == att_align_nominal(off, att->attalign))
att->attcacheoff = off;
else
{
off = att_align_pointer(off, att[i]->attalign, -1,
off = att_align_pointer(off, att->attalign, -1,
tp + off);
usecache = false;
}
@@ -387,23 +391,23 @@ nocache_index_getattr(IndexTuple tup,
else
{
/* not varlena, so safe to use att_align_nominal */
off = att_align_nominal(off, att[i]->attalign);
off = att_align_nominal(off, att->attalign);
if (usecache)
att[i]->attcacheoff = off;
att->attcacheoff = off;
}
if (i == attnum)
break;
off = att_addlength_pointer(off, att[i]->attlen, tp + off);
off = att_addlength_pointer(off, att->attlen, tp + off);
if (usecache && att[i]->attlen <= 0)
if (usecache && att->attlen <= 0)
usecache = false;
}
}
return fetchatt(att[attnum], tp + off);
return fetchatt(TupleDescAttr(tupleDesc, attnum), tp + off);
}
/*

View File

@@ -38,7 +38,7 @@ printsimple_startup(DestReceiver *self, int operation, TupleDesc tupdesc)
for (i = 0; i < tupdesc->natts; ++i)
{
Form_pg_attribute attr = tupdesc->attrs[i];
Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
pq_sendstring(&buf, NameStr(attr->attname));
pq_sendint(&buf, 0, 4); /* table oid */
@@ -71,7 +71,7 @@ printsimple(TupleTableSlot *slot, DestReceiver *self)
for (i = 0; i < tupdesc->natts; ++i)
{
Form_pg_attribute attr = tupdesc->attrs[i];
Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
Datum value;
if (slot->tts_isnull[i])

View File

@@ -187,7 +187,6 @@ printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
void
SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats)
{
Form_pg_attribute *attrs = typeinfo->attrs;
int natts = typeinfo->natts;
int proto = PG_PROTOCOL_MAJOR(FrontendProtocol);
int i;
@@ -199,10 +198,11 @@ SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats)
for (i = 0; i < natts; ++i)
{
Oid atttypid = attrs[i]->atttypid;
int32 atttypmod = attrs[i]->atttypmod;
Form_pg_attribute att = TupleDescAttr(typeinfo, i);
Oid atttypid = att->atttypid;
int32 atttypmod = att->atttypmod;
pq_sendstring(&buf, NameStr(attrs[i]->attname));
pq_sendstring(&buf, NameStr(att->attname));
/* column ID info appears in protocol 3.0 and up */
if (proto >= 3)
{
@@ -228,7 +228,7 @@ SendRowDescriptionMessage(TupleDesc typeinfo, List *targetlist, int16 *formats)
/* If column is a domain, send the base type and typmod instead */
atttypid = getBaseTypeAndTypmod(atttypid, &atttypmod);
pq_sendint(&buf, (int) atttypid, sizeof(atttypid));
pq_sendint(&buf, attrs[i]->attlen, sizeof(attrs[i]->attlen));
pq_sendint(&buf, att->attlen, sizeof(att->attlen));
pq_sendint(&buf, atttypmod, sizeof(atttypmod));
/* format info appears in protocol 3.0 and up */
if (proto >= 3)
@@ -268,18 +268,19 @@ printtup_prepare_info(DR_printtup *myState, TupleDesc typeinfo, int numAttrs)
{
PrinttupAttrInfo *thisState = myState->myinfo + i;
int16 format = (formats ? formats[i] : 0);
Form_pg_attribute attr = TupleDescAttr(typeinfo, i);
thisState->format = format;
if (format == 0)
{
getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
getTypeOutputInfo(attr->atttypid,
&thisState->typoutput,
&thisState->typisvarlena);
fmgr_info(thisState->typoutput, &thisState->finfo);
}
else if (format == 1)
{
getTypeBinaryOutputInfo(typeinfo->attrs[i]->atttypid,
getTypeBinaryOutputInfo(attr->atttypid,
&thisState->typsend,
&thisState->typisvarlena);
fmgr_info(thisState->typsend, &thisState->finfo);
@@ -513,14 +514,13 @@ void
debugStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
{
int natts = typeinfo->natts;
Form_pg_attribute *attinfo = typeinfo->attrs;
int i;
/*
* show the return type of the tuples
*/
for (i = 0; i < natts; ++i)
printatt((unsigned) i + 1, attinfo[i], NULL);
printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), NULL);
printf("\t----\n");
}
@@ -545,12 +545,12 @@ debugtup(TupleTableSlot *slot, DestReceiver *self)
attr = slot_getattr(slot, i + 1, &isnull);
if (isnull)
continue;
getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
&typoutput, &typisvarlena);
value = OidOutputFunctionCall(typoutput, attr);
printatt((unsigned) i + 1, typeinfo->attrs[i], value);
printatt((unsigned) i + 1, TupleDescAttr(typeinfo, i), value);
}
printf("\t----\n");

View File

@@ -84,7 +84,7 @@ convert_tuples_by_position(TupleDesc indesc,
same = true;
for (i = 0; i < n; i++)
{
Form_pg_attribute att = outdesc->attrs[i];
Form_pg_attribute att = TupleDescAttr(outdesc, i);
Oid atttypid;
int32 atttypmod;
@@ -95,7 +95,7 @@ convert_tuples_by_position(TupleDesc indesc,
atttypmod = att->atttypmod;
for (; j < indesc->natts; j++)
{
att = indesc->attrs[j];
att = TupleDescAttr(indesc, j);
if (att->attisdropped)
continue;
nincols++;
@@ -122,7 +122,7 @@ convert_tuples_by_position(TupleDesc indesc,
/* Check for unused input columns */
for (; j < indesc->natts; j++)
{
if (indesc->attrs[j]->attisdropped)
if (TupleDescAttr(indesc, j)->attisdropped)
continue;
nincols++;
same = false; /* we'll complain below */
@@ -149,6 +149,9 @@ convert_tuples_by_position(TupleDesc indesc,
{
for (i = 0; i < n; i++)
{
Form_pg_attribute inatt;
Form_pg_attribute outatt;
if (attrMap[i] == (i + 1))
continue;
@@ -157,10 +160,12 @@ convert_tuples_by_position(TupleDesc indesc,
* also dropped, we needn't convert. However, attlen and attalign
* must agree.
*/
inatt = TupleDescAttr(indesc, i);
outatt = TupleDescAttr(outdesc, i);
if (attrMap[i] == 0 &&
indesc->attrs[i]->attisdropped &&
indesc->attrs[i]->attlen == outdesc->attrs[i]->attlen &&
indesc->attrs[i]->attalign == outdesc->attrs[i]->attalign)
inatt->attisdropped &&
inatt->attlen == outatt->attlen &&
inatt->attalign == outatt->attalign)
continue;
same = false;
@@ -228,6 +233,9 @@ convert_tuples_by_name(TupleDesc indesc,
same = true;
for (i = 0; i < n; i++)
{
Form_pg_attribute inatt;
Form_pg_attribute outatt;
if (attrMap[i] == (i + 1))
continue;
@@ -236,10 +244,12 @@ convert_tuples_by_name(TupleDesc indesc,
* also dropped, we needn't convert. However, attlen and attalign
* must agree.
*/
inatt = TupleDescAttr(indesc, i);
outatt = TupleDescAttr(outdesc, i);
if (attrMap[i] == 0 &&
indesc->attrs[i]->attisdropped &&
indesc->attrs[i]->attlen == outdesc->attrs[i]->attlen &&
indesc->attrs[i]->attalign == outdesc->attrs[i]->attalign)
inatt->attisdropped &&
inatt->attlen == outatt->attlen &&
inatt->attalign == outatt->attalign)
continue;
same = false;
@@ -292,26 +302,27 @@ convert_tuples_by_name_map(TupleDesc indesc,
attrMap = (AttrNumber *) palloc0(n * sizeof(AttrNumber));
for (i = 0; i < n; i++)
{
Form_pg_attribute att = outdesc->attrs[i];
Form_pg_attribute outatt = TupleDescAttr(outdesc, i);
char *attname;
Oid atttypid;
int32 atttypmod;
int j;
if (att->attisdropped)
if (outatt->attisdropped)
continue; /* attrMap[i] is already 0 */
attname = NameStr(att->attname);
atttypid = att->atttypid;
atttypmod = att->atttypmod;
attname = NameStr(outatt->attname);
atttypid = outatt->atttypid;
atttypmod = outatt->atttypmod;
for (j = 0; j < indesc->natts; j++)
{
att = indesc->attrs[j];
if (att->attisdropped)
Form_pg_attribute inatt = TupleDescAttr(indesc, j);
if (inatt->attisdropped)
continue;
if (strcmp(attname, NameStr(att->attname)) == 0)
if (strcmp(attname, NameStr(inatt->attname)) == 0)
{
/* Found it, check type */
if (atttypid != att->atttypid || atttypmod != att->atttypmod)
if (atttypid != inatt->atttypid || atttypmod != inatt->atttypmod)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg_internal("%s", _(msg)),

View File

@@ -175,7 +175,9 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
for (i = 0; i < desc->natts; i++)
{
memcpy(desc->attrs[i], tupdesc->attrs[i], ATTRIBUTE_FIXED_PART_SIZE);
memcpy(TupleDescAttr(desc, i),
TupleDescAttr(tupdesc, i),
ATTRIBUTE_FIXED_PART_SIZE);
}
if (constr)
@@ -230,6 +232,9 @@ void
TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
TupleDesc src, AttrNumber srcAttno)
{
Form_pg_attribute dstAtt = TupleDescAttr(dst, dstAttno - 1);
Form_pg_attribute srcAtt = TupleDescAttr(src, srcAttno - 1);
/*
* sanity checks
*/
@@ -240,8 +245,7 @@ TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
AssertArg(dstAttno >= 1);
AssertArg(dstAttno <= dst->natts);
memcpy(dst->attrs[dstAttno - 1], src->attrs[srcAttno - 1],
ATTRIBUTE_FIXED_PART_SIZE);
memcpy(dstAtt, srcAtt, ATTRIBUTE_FIXED_PART_SIZE);
/*
* Aside from updating the attno, we'd better reset attcacheoff.
@@ -252,13 +256,13 @@ TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
* by other uses of this function or TupleDescInitEntry. So we cheat a
* bit to avoid a useless O(N^2) penalty.
*/
dst->attrs[dstAttno - 1]->attnum = dstAttno;
dst->attrs[dstAttno - 1]->attcacheoff = -1;
dstAtt->attnum = dstAttno;
dstAtt->attcacheoff = -1;
/* since we're not copying constraints or defaults, clear these */
dst->attrs[dstAttno - 1]->attnotnull = false;
dst->attrs[dstAttno - 1]->atthasdef = false;
dst->attrs[dstAttno - 1]->attidentity = '\0';
dstAtt->attnotnull = false;
dstAtt->atthasdef = false;
dstAtt->attidentity = '\0';
}
/*
@@ -366,8 +370,8 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
for (i = 0; i < tupdesc1->natts; i++)
{
Form_pg_attribute attr1 = tupdesc1->attrs[i];
Form_pg_attribute attr2 = tupdesc2->attrs[i];
Form_pg_attribute attr1 = TupleDescAttr(tupdesc1, i);
Form_pg_attribute attr2 = TupleDescAttr(tupdesc2, i);
/*
* We do not need to check every single field here: we can disregard
@@ -515,7 +519,7 @@ TupleDescInitEntry(TupleDesc desc,
/*
* initialize the attribute fields
*/
att = desc->attrs[attributeNumber - 1];
att = TupleDescAttr(desc, attributeNumber - 1);
att->attrelid = 0; /* dummy value */
@@ -580,7 +584,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
AssertArg(attributeNumber <= desc->natts);
/* initialize the attribute fields */
att = desc->attrs[attributeNumber - 1];
att = TupleDescAttr(desc, attributeNumber - 1);
att->attrelid = 0; /* dummy value */
/* unlike TupleDescInitEntry, we require an attribute name */
@@ -664,7 +668,7 @@ TupleDescInitEntryCollation(TupleDesc desc,
AssertArg(attributeNumber >= 1);
AssertArg(attributeNumber <= desc->natts);
desc->attrs[attributeNumber - 1]->attcollation = collationid;
TupleDescAttr(desc, attributeNumber - 1)->attcollation = collationid;
}
@@ -704,6 +708,7 @@ BuildDescForRelation(List *schema)
{
ColumnDef *entry = lfirst(l);
AclResult aclresult;
Form_pg_attribute att;
/*
* for each entry in the list, get the name and type information from
@@ -730,17 +735,18 @@ BuildDescForRelation(List *schema)
TupleDescInitEntry(desc, attnum, attname,
atttypid, atttypmod, attdim);
att = TupleDescAttr(desc, attnum - 1);
/* Override TupleDescInitEntry's settings as requested */
TupleDescInitEntryCollation(desc, attnum, attcollation);
if (entry->storage)
desc->attrs[attnum - 1]->attstorage = entry->storage;
att->attstorage = entry->storage;
/* Fill in additional stuff not handled by TupleDescInitEntry */
desc->attrs[attnum - 1]->attnotnull = entry->is_not_null;
att->attnotnull = entry->is_not_null;
has_not_null |= entry->is_not_null;
desc->attrs[attnum - 1]->attislocal = entry->is_local;
desc->attrs[attnum - 1]->attinhcount = entry->inhcount;
att->attislocal = entry->is_local;
att->attinhcount = entry->inhcount;
}
if (has_not_null)