summaryrefslogtreecommitdiff
path: root/src/backend/access
diff options
context:
space:
mode:
authorAndres Freund2017-08-20 18:19:07 +0000
committerAndres Freund2017-08-20 18:19:07 +0000
commit2cd70845240087da205695baedab6412342d1dbe (patch)
tree20a3b6a2231dae248218ac54983c7a854328265f /src/backend/access
parentb1c2d76a2fcef812af0be3343082414d401909c8 (diff)
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
Diffstat (limited to 'src/backend/access')
-rw-r--r--src/backend/access/brin/brin.c10
-rw-r--r--src/backend/access/brin/brin_inclusion.c6
-rw-r--r--src/backend/access/brin/brin_minmax.c6
-rw-r--r--src/backend/access/brin/brin_tuple.c2
-rw-r--r--src/backend/access/common/heaptuple.c95
-rw-r--r--src/backend/access/common/indextuple.c58
-rw-r--r--src/backend/access/common/printsimple.c4
-rw-r--r--src/backend/access/common/printtup.c22
-rw-r--r--src/backend/access/common/tupconvert.c47
-rw-r--r--src/backend/access/common/tupdesc.c40
-rw-r--r--src/backend/access/gin/ginbulk.c3
-rw-r--r--src/backend/access/gin/ginget.c2
-rw-r--r--src/backend/access/gin/ginutil.c14
-rw-r--r--src/backend/access/gist/gistbuild.c4
-rw-r--r--src/backend/access/heap/heapam.c8
-rw-r--r--src/backend/access/heap/tuptoaster.c38
-rw-r--r--src/backend/access/spgist/spgutils.c2
17 files changed, 193 insertions, 168 deletions
diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c
index efebeb035ac..b3aa6d1cedc 100644
--- a/src/backend/access/brin/brin.c
+++ b/src/backend/access/brin/brin.c
@@ -473,7 +473,8 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
*/
Assert((key->sk_flags & SK_ISNULL) ||
(key->sk_collation ==
- bdesc->bd_tupdesc->attrs[keyattno - 1]->attcollation));
+ TupleDescAttr(bdesc->bd_tupdesc,
+ keyattno - 1)->attcollation));
/* First time this column? look up consistent function */
if (consistentFn[keyattno - 1].fn_oid == InvalidOid)
@@ -622,6 +623,7 @@ brinbuildCallback(Relation index,
{
FmgrInfo *addValue;
BrinValues *col;
+ Form_pg_attribute attr = TupleDescAttr(state->bs_bdesc->bd_tupdesc, i);
col = &state->bs_dtuple->bt_columns[i];
addValue = index_getprocinfo(index, i + 1,
@@ -631,7 +633,7 @@ brinbuildCallback(Relation index,
* Update dtuple state, if and as necessary.
*/
FunctionCall4Coll(addValue,
- state->bs_bdesc->bd_tupdesc->attrs[i]->attcollation,
+ attr->attcollation,
PointerGetDatum(state->bs_bdesc),
PointerGetDatum(col),
values[i], isnull[i]);
@@ -1019,12 +1021,12 @@ brin_build_desc(Relation rel)
for (keyno = 0; keyno < tupdesc->natts; keyno++)
{
FmgrInfo *opcInfoFn;
+ Form_pg_attribute attr = TupleDescAttr(tupdesc, keyno);
opcInfoFn = index_getprocinfo(rel, keyno + 1, BRIN_PROCNUM_OPCINFO);
opcinfo[keyno] = (BrinOpcInfo *)
- DatumGetPointer(FunctionCall1(opcInfoFn,
- tupdesc->attrs[keyno]->atttypid));
+ DatumGetPointer(FunctionCall1(opcInfoFn, attr->atttypid));
totalstored += opcinfo[keyno]->oi_nstored;
}
diff --git a/src/backend/access/brin/brin_inclusion.c b/src/backend/access/brin/brin_inclusion.c
index 9c0a058ccb0..449ce5ea4cf 100644
--- a/src/backend/access/brin/brin_inclusion.c
+++ b/src/backend/access/brin/brin_inclusion.c
@@ -157,7 +157,7 @@ brin_inclusion_add_value(PG_FUNCTION_ARGS)
}
attno = column->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* If the recorded value is null, copy the new value (which we know to be
@@ -516,7 +516,7 @@ brin_inclusion_union(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
attno = col_a->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* Adjust "allnulls". If A doesn't have values, just copy the values from
@@ -675,7 +675,7 @@ inclusion_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
bool isNull;
opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
tuple = SearchSysCache4(AMOPSTRATEGY, ObjectIdGetDatum(opfamily),
ObjectIdGetDatum(attr->atttypid),
ObjectIdGetDatum(subtype),
diff --git a/src/backend/access/brin/brin_minmax.c b/src/backend/access/brin/brin_minmax.c
index 62fd90aabe7..ce503972f89 100644
--- a/src/backend/access/brin/brin_minmax.c
+++ b/src/backend/access/brin/brin_minmax.c
@@ -90,7 +90,7 @@ brin_minmax_add_value(PG_FUNCTION_ARGS)
}
attno = column->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* If the recorded value is null, store the new value (which we know to be
@@ -260,7 +260,7 @@ brin_minmax_union(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
attno = col_a->bv_attno;
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
/*
* Adjust "allnulls". If A doesn't have values, just copy the values from
@@ -347,7 +347,7 @@ minmax_get_strategy_procinfo(BrinDesc *bdesc, uint16 attno, Oid subtype,
bool isNull;
opfamily = bdesc->bd_index->rd_opfamily[attno - 1];
- attr = bdesc->bd_tupdesc->attrs[attno - 1];
+ attr = TupleDescAttr(bdesc->bd_tupdesc, attno - 1);
tuple = SearchSysCache4(AMOPSTRATEGY, ObjectIdGetDatum(opfamily),
ObjectIdGetDatum(attr->atttypid),
ObjectIdGetDatum(subtype),
diff --git a/src/backend/access/brin/brin_tuple.c b/src/backend/access/brin/brin_tuple.c
index ed5b4b108da..5c035fb2033 100644
--- a/src/backend/access/brin/brin_tuple.c
+++ b/src/backend/access/brin/brin_tuple.c
@@ -559,7 +559,7 @@ brin_deconstruct_tuple(BrinDesc *brdesc,
datumno < brdesc->bd_info[attnum]->oi_nstored;
datumno++)
{
- Form_pg_attribute thisatt = diskdsc->attrs[stored];
+ Form_pg_attribute thisatt = TupleDescAttr(diskdsc, stored);
if (thisatt->attlen == -1)
{
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 584a202ab51..13ee528e261 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -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;
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index 37a21057d00..138671410a2 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -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);
}
/*
diff --git a/src/backend/access/common/printsimple.c b/src/backend/access/common/printsimple.c
index c863e859fef..b3e9a26b032 100644
--- a/src/backend/access/common/printsimple.c
+++ b/src/backend/access/common/printsimple.c
@@ -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])
diff --git a/src/backend/access/common/printtup.c b/src/backend/access/common/printtup.c
index a2ca2d74aef..20d20e623e8 100644
--- a/src/backend/access/common/printtup.c
+++ b/src/backend/access/common/printtup.c
@@ -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");
diff --git a/src/backend/access/common/tupconvert.c b/src/backend/access/common/tupconvert.c
index 57e44375eab..3d1bc0635bf 100644
--- a/src/backend/access/common/tupconvert.c
+++ b/src/backend/access/common/tupconvert.c
@@ -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)),
diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c
index 9fd7b4e019b..a5df2d64e28 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -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)
diff --git a/src/backend/access/gin/ginbulk.c b/src/backend/access/gin/ginbulk.c
index 4ff149e59af..c76f5042950 100644
--- a/src/backend/access/gin/ginbulk.c
+++ b/src/backend/access/gin/ginbulk.c
@@ -127,9 +127,10 @@ ginInitBA(BuildAccumulator *accum)
static Datum
getDatumCopy(BuildAccumulator *accum, OffsetNumber attnum, Datum value)
{
- Form_pg_attribute att = accum->ginstate->origTupdesc->attrs[attnum - 1];
+ Form_pg_attribute att;
Datum res;
+ att = TupleDescAttr(accum->ginstate->origTupdesc, attnum - 1);
if (att->attbyval)
res = value;
else
diff --git a/src/backend/access/gin/ginget.c b/src/backend/access/gin/ginget.c
index 56a5bf47b8c..98950806852 100644
--- a/src/backend/access/gin/ginget.c
+++ b/src/backend/access/gin/ginget.c
@@ -129,7 +129,7 @@ collectMatchBitmap(GinBtreeData *btree, GinBtreeStack *stack,
/* Locate tupdesc entry for key column (for attbyval/attlen data) */
attnum = scanEntry->attnum;
- attr = btree->ginstate->origTupdesc->attrs[attnum - 1];
+ attr = TupleDescAttr(btree->ginstate->origTupdesc, attnum - 1);
for (;;)
{
diff --git a/src/backend/access/gin/ginutil.c b/src/backend/access/gin/ginutil.c
index 91e4a8cf700..136ea277180 100644
--- a/src/backend/access/gin/ginutil.c
+++ b/src/backend/access/gin/ginutil.c
@@ -96,6 +96,8 @@ initGinState(GinState *state, Relation index)
for (i = 0; i < origTupdesc->natts; i++)
{
+ Form_pg_attribute attr = TupleDescAttr(origTupdesc, i);
+
if (state->oneCol)
state->tupdesc[i] = state->origTupdesc;
else
@@ -105,11 +107,11 @@ initGinState(GinState *state, Relation index)
TupleDescInitEntry(state->tupdesc[i], (AttrNumber) 1, NULL,
INT2OID, -1, 0);
TupleDescInitEntry(state->tupdesc[i], (AttrNumber) 2, NULL,
- origTupdesc->attrs[i]->atttypid,
- origTupdesc->attrs[i]->atttypmod,
- origTupdesc->attrs[i]->attndims);
+ attr->atttypid,
+ attr->atttypmod,
+ attr->attndims);
TupleDescInitEntryCollation(state->tupdesc[i], (AttrNumber) 2,
- origTupdesc->attrs[i]->attcollation);
+ attr->attcollation);
}
/*
@@ -126,13 +128,13 @@ initGinState(GinState *state, Relation index)
{
TypeCacheEntry *typentry;
- typentry = lookup_type_cache(origTupdesc->attrs[i]->atttypid,
+ typentry = lookup_type_cache(attr->atttypid,
TYPECACHE_CMP_PROC_FINFO);
if (!OidIsValid(typentry->cmp_proc_finfo.fn_oid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("could not identify a comparison function for type %s",
- format_type_be(origTupdesc->attrs[i]->atttypid))));
+ format_type_be(attr->atttypid))));
fmgr_info_copy(&(state->compareFn[i]),
&(typentry->cmp_proc_finfo),
CurrentMemoryContext);
diff --git a/src/backend/access/gist/gistbuild.c b/src/backend/access/gist/gistbuild.c
index 4756a70ae6d..b4cb3648690 100644
--- a/src/backend/access/gist/gistbuild.c
+++ b/src/backend/access/gist/gistbuild.c
@@ -295,10 +295,10 @@ gistInitBuffering(GISTBuildState *buildstate)
itupMinSize = (Size) MAXALIGN(sizeof(IndexTupleData));
for (i = 0; i < index->rd_att->natts; i++)
{
- if (index->rd_att->attrs[i]->attlen < 0)
+ if (TupleDescAttr(index->rd_att, i)->attlen < 0)
itupMinSize += VARHDRSZ;
else
- itupMinSize += index->rd_att->attrs[i]->attlen;
+ itupMinSize += TupleDescAttr(index->rd_att, i)->attlen;
}
/* Calculate average and maximal number of index tuples which fit to page */
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 8792f1453cb..ff03c68fcdb 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -1066,11 +1066,11 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
(*(isnull) = false),
HeapTupleNoNulls(tup) ?
(
- (tupleDesc)->attrs[(attnum) - 1]->attcacheoff >= 0 ?
+ TupleDescAttr((tupleDesc), (attnum) - 1)->attcacheoff >= 0 ?
(
- fetchatt((tupleDesc)->attrs[(attnum) - 1],
+ fetchatt(TupleDescAttr((tupleDesc), (attnum) - 1),
(char *) (tup)->t_data + (tup)->t_data->t_hoff +
- (tupleDesc)->attrs[(attnum) - 1]->attcacheoff)
+ TupleDescAttr((tupleDesc), (attnum) - 1)->attcacheoff)
)
:
nocachegetattr((tup), (attnum), (tupleDesc))
@@ -4422,7 +4422,7 @@ heap_tuple_attr_equals(TupleDesc tupdesc, int attrnum,
else
{
Assert(attrnum <= tupdesc->natts);
- att = tupdesc->attrs[attrnum - 1];
+ att = TupleDescAttr(tupdesc, attrnum - 1);
return datumIsEqual(value1, value2, att->attbyval, att->attlen);
}
}
diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c
index 458180bc95f..5a8f1dab83b 100644
--- a/src/backend/access/heap/tuptoaster.c
+++ b/src/backend/access/heap/tuptoaster.c
@@ -464,7 +464,6 @@ void
toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative)
{
TupleDesc tupleDesc;
- Form_pg_attribute *att;
int numAttrs;
int i;
Datum toast_values[MaxHeapAttributeNumber];
@@ -489,7 +488,6 @@ toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative)
* least one varlena column, by the way.)
*/
tupleDesc = rel->rd_att;
- att = tupleDesc->attrs;
numAttrs = tupleDesc->natts;
Assert(numAttrs <= MaxHeapAttributeNumber);
@@ -501,7 +499,7 @@ toast_delete(Relation rel, HeapTuple oldtup, bool is_speculative)
*/
for (i = 0; i < numAttrs; i++)
{
- if (att[i]->attlen == -1)
+ if (TupleDescAttr(tupleDesc, i)->attlen == -1)
{
Datum value = toast_values[i];
@@ -538,7 +536,6 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
{
HeapTuple result_tuple;
TupleDesc tupleDesc;
- Form_pg_attribute *att;
int numAttrs;
int i;
@@ -579,7 +576,6 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
* Get the tuple descriptor and break down the tuple(s) into fields.
*/
tupleDesc = rel->rd_att;
- att = tupleDesc->attrs;
numAttrs = tupleDesc->natts;
Assert(numAttrs <= MaxHeapAttributeNumber);
@@ -606,6 +602,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
for (i = 0; i < numAttrs; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
struct varlena *old_value;
struct varlena *new_value;
@@ -621,7 +618,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
* If the old value is stored on disk, check if it has changed so
* we have to delete it later.
*/
- if (att[i]->attlen == -1 && !toast_oldisnull[i] &&
+ if (att->attlen == -1 && !toast_oldisnull[i] &&
VARATT_IS_EXTERNAL_ONDISK(old_value))
{
if (toast_isnull[i] || !VARATT_IS_EXTERNAL_ONDISK(new_value) ||
@@ -668,12 +665,12 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
/*
* Now look at varlena attributes
*/
- if (att[i]->attlen == -1)
+ if (att->attlen == -1)
{
/*
* If the table's attribute says PLAIN always, force it so.
*/
- if (att[i]->attstorage == 'p')
+ if (att->attstorage == 'p')
toast_action[i] = 'p';
/*
@@ -687,7 +684,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
if (VARATT_IS_EXTERNAL(new_value))
{
toast_oldexternal[i] = new_value;
- if (att[i]->attstorage == 'p')
+ if (att->attstorage == 'p')
new_value = heap_tuple_untoast_attr(new_value);
else
new_value = heap_tuple_fetch_attr(new_value);
@@ -749,13 +746,15 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
*/
for (i = 0; i < numAttrs; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
+
if (toast_action[i] != ' ')
continue;
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
continue;
- if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
+ if (att->attstorage != 'x' && att->attstorage != 'e')
continue;
if (toast_sizes[i] > biggest_size)
{
@@ -771,7 +770,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
* Attempt to compress it inline, if it has attstorage 'x'
*/
i = biggest_attno;
- if (att[i]->attstorage == 'x')
+ if (TupleDescAttr(tupleDesc, i)->attstorage == 'x')
{
old_value = toast_values[i];
new_value = toast_compress_datum(old_value);
@@ -841,11 +840,13 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
*/
for (i = 0; i < numAttrs; i++)
{
+ Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
+
if (toast_action[i] == 'p')
continue;
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
- if (att[i]->attstorage != 'x' && att[i]->attstorage != 'e')
+ if (att->attstorage != 'x' && att->attstorage != 'e')
continue;
if (toast_sizes[i] > biggest_size)
{
@@ -896,7 +897,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
continue; /* can't happen, toast_action would be 'p' */
if (VARATT_IS_COMPRESSED(DatumGetPointer(toast_values[i])))
continue;
- if (att[i]->attstorage != 'm')
+ if (TupleDescAttr(tupleDesc, i)->attstorage != 'm')
continue;
if (toast_sizes[i] > biggest_size)
{
@@ -959,7 +960,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup,
continue;
if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
continue; /* can't happen, toast_action would be 'p' */
- if (att[i]->attstorage != 'm')
+ if (TupleDescAttr(tupleDesc, i)->attstorage != 'm')
continue;
if (toast_sizes[i] > biggest_size)
{
@@ -1084,7 +1085,6 @@ HeapTuple
toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc)
{
HeapTuple new_tuple;
- Form_pg_attribute *att = tupleDesc->attrs;
int numAttrs = tupleDesc->natts;
int i;
Datum toast_values[MaxTupleAttributeNumber];
@@ -1104,7 +1104,7 @@ toast_flatten_tuple(HeapTuple tup, TupleDesc tupleDesc)
/*
* Look at non-null varlena attributes
*/
- if (!toast_isnull[i] && att[i]->attlen == -1)
+ if (!toast_isnull[i] && TupleDescAttr(tupleDesc, i)->attlen == -1)
{
struct varlena *new_value;
@@ -1193,7 +1193,6 @@ toast_flatten_tuple_to_datum(HeapTupleHeader tup,
int32 new_data_len;
int32 new_tuple_len;
HeapTupleData tmptup;
- Form_pg_attribute *att = tupleDesc->attrs;
int numAttrs = tupleDesc->natts;
int i;
bool has_nulls = false;
@@ -1222,7 +1221,7 @@ toast_flatten_tuple_to_datum(HeapTupleHeader tup,
*/
if (toast_isnull[i])
has_nulls = true;
- else if (att[i]->attlen == -1)
+ else if (TupleDescAttr(tupleDesc, i)->attlen == -1)
{
struct varlena *new_value;
@@ -1307,7 +1306,6 @@ toast_build_flattened_tuple(TupleDesc tupleDesc,
bool *isnull)
{
HeapTuple new_tuple;
- Form_pg_attribute *att = tupleDesc->attrs;
int numAttrs = tupleDesc->natts;
int num_to_free;
int i;
@@ -1327,7 +1325,7 @@ toast_build_flattened_tuple(TupleDesc tupleDesc,
/*
* Look at non-null varlena attributes
*/
- if (!isnull[i] && att[i]->attlen == -1)
+ if (!isnull[i] && TupleDescAttr(tupleDesc, i)->attlen == -1)
{
struct varlena *new_value;
diff --git a/src/backend/access/spgist/spgutils.c b/src/backend/access/spgist/spgutils.c
index 8656af453c1..22f64b0103c 100644
--- a/src/backend/access/spgist/spgutils.c
+++ b/src/backend/access/spgist/spgutils.c
@@ -112,7 +112,7 @@ spgGetCache(Relation index)
* tupdesc. We pass this to the opclass config function so that
* polymorphic opclasses are possible.
*/
- atttype = index->rd_att->attrs[0]->atttypid;
+ atttype = TupleDescAttr(index->rd_att, 0)->atttypid;
/* Call the config function to get config info for the opclass */
in.attType = atttype;