Skip to content

Commit 2cd7084

Browse files
committedAug 20, 2017
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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+805
-626
lines changed
 

‎contrib/dblink/dblink.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,14 +2172,16 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
21722172
needComma = false;
21732173
for (i = 0; i < natts; i++)
21742174
{
2175-
if (tupdesc->attrs[i]->attisdropped)
2175+
Form_pg_attribute att = TupleDescAttr(tupdesc, i);
2176+
2177+
if (att->attisdropped)
21762178
continue;
21772179

21782180
if (needComma)
21792181
appendStringInfoChar(&buf, ',');
21802182

21812183
appendStringInfoString(&buf,
2182-
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
2184+
quote_ident_cstr(NameStr(att->attname)));
21832185
needComma = true;
21842186
}
21852187

@@ -2191,7 +2193,7 @@ get_sql_insert(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
21912193
needComma = false;
21922194
for (i = 0; i < natts; i++)
21932195
{
2194-
if (tupdesc->attrs[i]->attisdropped)
2196+
if (TupleDescAttr(tupdesc, i)->attisdropped)
21952197
continue;
21962198

21972199
if (needComma)
@@ -2237,12 +2239,13 @@ get_sql_delete(Relation rel, int *pkattnums, int pknumatts, char **tgt_pkattvals
22372239
for (i = 0; i < pknumatts; i++)
22382240
{
22392241
int pkattnum = pkattnums[i];
2242+
Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
22402243

22412244
if (i > 0)
22422245
appendStringInfoString(&buf, " AND ");
22432246

22442247
appendStringInfoString(&buf,
2245-
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
2248+
quote_ident_cstr(NameStr(attr->attname)));
22462249

22472250
if (tgt_pkattvals[i] != NULL)
22482251
appendStringInfo(&buf, " = %s",
@@ -2289,14 +2292,16 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
22892292
needComma = false;
22902293
for (i = 0; i < natts; i++)
22912294
{
2292-
if (tupdesc->attrs[i]->attisdropped)
2295+
Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
2296+
2297+
if (attr->attisdropped)
22932298
continue;
22942299

22952300
if (needComma)
22962301
appendStringInfoString(&buf, ", ");
22972302

22982303
appendStringInfo(&buf, "%s = ",
2299-
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
2304+
quote_ident_cstr(NameStr(attr->attname)));
23002305

23012306
key = get_attnum_pk_pos(pkattnums, pknumatts, i);
23022307

@@ -2320,12 +2325,13 @@ get_sql_update(Relation rel, int *pkattnums, int pknumatts, char **src_pkattvals
23202325
for (i = 0; i < pknumatts; i++)
23212326
{
23222327
int pkattnum = pkattnums[i];
2328+
Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
23232329

23242330
if (i > 0)
23252331
appendStringInfoString(&buf, " AND ");
23262332

23272333
appendStringInfoString(&buf,
2328-
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
2334+
quote_ident_cstr(NameStr(attr->attname)));
23292335

23302336
val = tgt_pkattvals[i];
23312337

@@ -2409,27 +2415,30 @@ get_tuple_of_interest(Relation rel, int *pkattnums, int pknumatts, char **src_pk
24092415

24102416
for (i = 0; i < natts; i++)
24112417
{
2418+
Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
2419+
24122420
if (i > 0)
24132421
appendStringInfoString(&buf, ", ");
24142422

2415-
if (tupdesc->attrs[i]->attisdropped)
2423+
if (attr->attisdropped)
24162424
appendStringInfoString(&buf, "NULL");
24172425
else
24182426
appendStringInfoString(&buf,
2419-
quote_ident_cstr(NameStr(tupdesc->attrs[i]->attname)));
2427+
quote_ident_cstr(NameStr(attr->attname)));
24202428
}
24212429

24222430
appendStringInfo(&buf, " FROM %s WHERE ", relname);
24232431

24242432
for (i = 0; i < pknumatts; i++)
24252433
{
24262434
int pkattnum = pkattnums[i];
2435+
Form_pg_attribute attr = TupleDescAttr(tupdesc, pkattnum);
24272436

24282437
if (i > 0)
24292438
appendStringInfoString(&buf, " AND ");
24302439

24312440
appendStringInfoString(&buf,
2432-
quote_ident_cstr(NameStr(tupdesc->attrs[pkattnum]->attname)));
2441+
quote_ident_cstr(NameStr(attr->attname)));
24332442

24342443
if (src_pkattvals[i] != NULL)
24352444
appendStringInfo(&buf, " = %s",
@@ -2894,7 +2903,7 @@ validate_pkattnums(Relation rel,
28942903
for (j = 0; j < natts; j++)
28952904
{
28962905
/* dropped columns don't count */
2897-
if (tupdesc->attrs[j]->attisdropped)
2906+
if (TupleDescAttr(tupdesc, j)->attisdropped)
28982907
continue;
28992908

29002909
if (++lnum == pkattnum)

‎contrib/file_fdw/file_fdw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ get_file_fdw_attribute_options(Oid relid)
430430
/* Retrieve FDW options for all user-defined attributes. */
431431
for (attnum = 1; attnum <= natts; attnum++)
432432
{
433-
Form_pg_attribute attr = tupleDesc->attrs[attnum - 1];
433+
Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
434434
List *options;
435435
ListCell *lc;
436436

@@ -898,7 +898,7 @@ check_selective_binary_conversion(RelOptInfo *baserel,
898898
/* Get user attributes. */
899899
if (attnum > 0)
900900
{
901-
Form_pg_attribute attr = tupleDesc->attrs[attnum - 1];
901+
Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum - 1);
902902
char *attname = NameStr(attr->attname);
903903

904904
/* Skip dropped attributes (probably shouldn't see any here). */
@@ -912,7 +912,7 @@ check_selective_binary_conversion(RelOptInfo *baserel,
912912
numattrs = 0;
913913
for (i = 0; i < tupleDesc->natts; i++)
914914
{
915-
Form_pg_attribute attr = tupleDesc->attrs[i];
915+
Form_pg_attribute attr = TupleDescAttr(tupleDesc, i);
916916

917917
if (attr->attisdropped)
918918
continue;

0 commit comments

Comments
 (0)
Please sign in to comment.