Skip to content

Commit 65b71de

Browse files
committed
Use TupleDescAttr macro consistently
A few places were directly accessing the attrs[] array. This goes against the standards set by 2cd7084. Fix that. Discussion: https://postgr.es/m/CAApHDvrBztXP3yx=NKNmo3xwFAFhEdyPnvrDg3=M0RhDs+4vYw@mail.gmail.com
1 parent 0c1aca4 commit 65b71de

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

contrib/pageinspect/gistfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ gist_page_items(PG_FUNCTION_ARGS)
309309
bool typisvarlena;
310310
Oid typoid;
311311

312-
typoid = tupdesc->attrs[i].atttypid;
312+
typoid = TupleDescAttr(tupdesc, i)->atttypid;
313313
getTypeOutputInfo(typoid, &foutoid, &typisvarlena);
314314
value = OidOutputFunctionCall(foutoid, itup_values[i]);
315315
}

src/backend/catalog/heap.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,18 +839,19 @@ AddNewAttributeTuples(Oid new_rel_oid,
839839
/* add dependencies on their datatypes and collations */
840840
for (int i = 0; i < natts; i++)
841841
{
842+
Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
843+
842844
/* Add dependency info */
843845
ObjectAddressSubSet(myself, RelationRelationId, new_rel_oid, i + 1);
844-
ObjectAddressSet(referenced, TypeRelationId,
845-
tupdesc->attrs[i].atttypid);
846+
ObjectAddressSet(referenced, TypeRelationId, attr->atttypid);
846847
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
847848

848849
/* The default collation is pinned, so don't bother recording it */
849-
if (OidIsValid(tupdesc->attrs[i].attcollation) &&
850-
tupdesc->attrs[i].attcollation != DEFAULT_COLLATION_OID)
850+
if (OidIsValid(attr->attcollation) &&
851+
attr->attcollation != DEFAULT_COLLATION_OID)
851852
{
852853
ObjectAddressSet(referenced, CollationRelationId,
853-
tupdesc->attrs[i].attcollation);
854+
attr->attcollation);
854855
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
855856
}
856857
}

src/backend/commands/prepare.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
717717

718718
result_types = palloc_array(Oid, result_desc->natts);
719719
for (int i = 0; i < result_desc->natts; i++)
720-
result_types[i] = result_desc->attrs[i].atttypid;
720+
result_types[i] = TupleDescAttr(result_desc, i)->atttypid;
721721
values[4] = build_regtype_array(result_types, result_desc->natts);
722722
}
723723
else

src/backend/executor/nodeIndexonlyscan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ ExecInitIndexOnlyScan(IndexOnlyScan *node, EState *estate, int eflags)
658658
/* First, count the number of such index keys */
659659
for (int attnum = 0; attnum < indnkeyatts; attnum++)
660660
{
661-
if (indexRelation->rd_att->attrs[attnum].atttypid == CSTRINGOID &&
661+
if (TupleDescAttr(indexRelation->rd_att, attnum)->atttypid == CSTRINGOID &&
662662
indexRelation->rd_opcintype[attnum] == NAMEOID)
663663
namecount++;
664664
}
@@ -676,7 +676,7 @@ ExecInitIndexOnlyScan(IndexOnlyScan *node, EState *estate, int eflags)
676676

677677
for (int attnum = 0; attnum < indnkeyatts; attnum++)
678678
{
679-
if (indexRelation->rd_att->attrs[attnum].atttypid == CSTRINGOID &&
679+
if (TupleDescAttr(indexRelation->rd_att, attnum)->atttypid == CSTRINGOID &&
680680
indexRelation->rd_opcintype[attnum] == NAMEOID)
681681
indexstate->ioss_NameCStringAttNums[idx++] = (AttrNumber) attnum;
682682
}

src/backend/executor/nodeMemoize.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ MemoizeHash_hash(struct memoize_hash *tb, const MemoizeKey *key)
175175

176176
if (!pslot->tts_isnull[i]) /* treat nulls as having hash key 0 */
177177
{
178-
FormData_pg_attribute *attr;
178+
Form_pg_attribute attr;
179179
uint32 hkey;
180180

181-
attr = &pslot->tts_tupleDescriptor->attrs[i];
181+
attr = TupleDescAttr(pslot->tts_tupleDescriptor, i);
182182

183183
hkey = datum_image_hash(pslot->tts_values[i], attr->attbyval, attr->attlen);
184184

@@ -242,7 +242,7 @@ MemoizeHash_equal(struct memoize_hash *tb, const MemoizeKey *key1,
242242

243243
for (int i = 0; i < numkeys; i++)
244244
{
245-
FormData_pg_attribute *attr;
245+
Form_pg_attribute attr;
246246

247247
if (tslot->tts_isnull[i] != pslot->tts_isnull[i])
248248
{
@@ -255,7 +255,7 @@ MemoizeHash_equal(struct memoize_hash *tb, const MemoizeKey *key1,
255255
continue;
256256

257257
/* perform binary comparison on the two datums */
258-
attr = &tslot->tts_tupleDescriptor->attrs[i];
258+
attr = TupleDescAttr(tslot->tts_tupleDescriptor, i);
259259
if (!datum_image_eq(tslot->tts_values[i], pslot->tts_values[i],
260260
attr->attbyval, attr->attlen))
261261
{

src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
174174
{
175175
for (int i = 0; i < relation->rd_att->natts; i++)
176176
{
177-
FormData_pg_attribute *attr = &relation->rd_att->attrs[i];
177+
Form_pg_attribute attr = TupleDescAttr(relation->rd_att, i);
178178

179179
if (attr->attnotnull)
180180
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy