Skip to content

Commit 2cd7084

Browse files
committed
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
1 parent b1c2d76 commit 2cd7084

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;

contrib/hstore/hstore_io.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -855,15 +855,16 @@ hstore_from_record(PG_FUNCTION_ARGS)
855855
for (i = 0, j = 0; i < ncolumns; ++i)
856856
{
857857
ColumnIOData *column_info = &my_extra->columns[i];
858-
Oid column_type = tupdesc->attrs[i]->atttypid;
858+
Form_pg_attribute att = TupleDescAttr(tupdesc, i);
859+
Oid column_type = att->atttypid;
859860
char *value;
860861

861862
/* Ignore dropped columns in datatype */
862-
if (tupdesc->attrs[i]->attisdropped)
863+
if (att->attisdropped)
863864
continue;
864865

865-
pairs[j].key = NameStr(tupdesc->attrs[i]->attname);
866-
pairs[j].keylen = hstoreCheckKeyLen(strlen(NameStr(tupdesc->attrs[i]->attname)));
866+
pairs[j].key = NameStr(att->attname);
867+
pairs[j].keylen = hstoreCheckKeyLen(strlen(NameStr(att->attname)));
867868

868869
if (!nulls || nulls[i])
869870
{
@@ -1034,21 +1035,22 @@ hstore_populate_record(PG_FUNCTION_ARGS)
10341035
for (i = 0; i < ncolumns; ++i)
10351036
{
10361037
ColumnIOData *column_info = &my_extra->columns[i];
1037-
Oid column_type = tupdesc->attrs[i]->atttypid;
1038+
Form_pg_attribute att = TupleDescAttr(tupdesc, i);
1039+
Oid column_type = att->atttypid;
10381040
char *value;
10391041
int idx;
10401042
int vallen;
10411043

10421044
/* Ignore dropped columns in datatype */
1043-
if (tupdesc->attrs[i]->attisdropped)
1045+
if (att->attisdropped)
10441046
{
10451047
nulls[i] = true;
10461048
continue;
10471049
}
10481050

10491051
idx = hstoreFindKey(hs, 0,
1050-
NameStr(tupdesc->attrs[i]->attname),
1051-
strlen(NameStr(tupdesc->attrs[i]->attname)));
1052+
NameStr(att->attname),
1053+
strlen(NameStr(att->attname)));
10521054

10531055
/*
10541056
* we can't just skip here if the key wasn't found since we might have
@@ -1082,7 +1084,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
10821084
*/
10831085
values[i] = InputFunctionCall(&column_info->proc, NULL,
10841086
column_info->typioparam,
1085-
tupdesc->attrs[i]->atttypmod);
1087+
att->atttypmod);
10861088
nulls[i] = true;
10871089
}
10881090
else
@@ -1094,7 +1096,7 @@ hstore_populate_record(PG_FUNCTION_ARGS)
10941096

10951097
values[i] = InputFunctionCall(&column_info->proc, value,
10961098
column_info->typioparam,
1097-
tupdesc->attrs[i]->atttypmod);
1099+
att->atttypmod);
10981100
nulls[i] = false;
10991101
}
11001102
}

contrib/pageinspect/heapfuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
316316
bool is_null;
317317
bytea *attr_data = NULL;
318318

319-
attr = tupdesc->attrs[i];
319+
attr = TupleDescAttr(tupdesc, i);
320320
is_null = (t_infomask & HEAP_HASNULL) && att_isnull(i, t_bits);
321321

322322
/*
@@ -334,7 +334,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
334334

335335
if (attr->attlen == -1)
336336
{
337-
off = att_align_pointer(off, tupdesc->attrs[i]->attalign, -1,
337+
off = att_align_pointer(off, attr->attalign, -1,
338338
tupdata + off);
339339

340340
/*
@@ -353,7 +353,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
353353
}
354354
else
355355
{
356-
off = att_align_nominal(off, tupdesc->attrs[i]->attalign);
356+
off = att_align_nominal(off, attr->attalign);
357357
len = attr->attlen;
358358
}
359359

@@ -371,7 +371,7 @@ tuple_data_split_internal(Oid relid, char *tupdata,
371371
memcpy(VARDATA(attr_data), tupdata + off, len);
372372
}
373373

374-
off = att_addlength_pointer(off, tupdesc->attrs[i]->attlen,
374+
off = att_addlength_pointer(off, attr->attlen,
375375
tupdata + off);
376376
}
377377

contrib/pageinspect/rawpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ page_header(PG_FUNCTION_ARGS)
253253
lsn = PageGetLSN(page);
254254

255255
/* pageinspect >= 1.2 uses pg_lsn instead of text for the LSN field. */
256-
if (tupdesc->attrs[0]->atttypid == TEXTOID)
256+
if (TupleDescAttr(tupdesc, 0)->atttypid == TEXTOID)
257257
{
258258
char lsnchar[64];
259259

contrib/postgres_fdw/deparse.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ deparseTargetList(StringInfo buf,
11151115
first = true;
11161116
for (i = 1; i <= tupdesc->natts; i++)
11171117
{
1118-
Form_pg_attribute attr = tupdesc->attrs[i - 1];
1118+
Form_pg_attribute attr = TupleDescAttr(tupdesc, i - 1);
11191119

11201120
/* Ignore dropped attributes. */
11211121
if (attr->attisdropped)
@@ -1851,15 +1851,15 @@ deparseAnalyzeSql(StringInfo buf, Relation rel, List **retrieved_attrs)
18511851
for (i = 0; i < tupdesc->natts; i++)
18521852
{
18531853
/* Ignore dropped columns. */
1854-
if (tupdesc->attrs[i]->attisdropped)
1854+
if (TupleDescAttr(tupdesc, i)->attisdropped)
18551855
continue;
18561856

18571857
if (!first)
18581858
appendStringInfoString(buf, ", ");
18591859
first = false;
18601860

18611861
/* Use attribute name or column_name option. */
1862-
colname = NameStr(tupdesc->attrs[i]->attname);
1862+
colname = NameStr(TupleDescAttr(tupdesc, i)->attname);
18631863
options = GetForeignColumnOptions(relid, i + 1);
18641864

18651865
foreach(lc, options)

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ postgresPlanForeignModify(PlannerInfo *root,
15751575

15761576
for (attnum = 1; attnum <= tupdesc->natts; attnum++)
15771577
{
1578-
Form_pg_attribute attr = tupdesc->attrs[attnum - 1];
1578+
Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
15791579

15801580
if (!attr->attisdropped)
15811581
targetAttrs = lappend_int(targetAttrs, attnum);
@@ -1675,6 +1675,7 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
16751675
Oid typefnoid;
16761676
bool isvarlena;
16771677
ListCell *lc;
1678+
TupleDesc tupdesc = RelationGetDescr(rel);
16781679

16791680
/*
16801681
* Do nothing in EXPLAIN (no ANALYZE) case. resultRelInfo->ri_FdwState
@@ -1719,7 +1720,7 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
17191720

17201721
/* Prepare for input conversion of RETURNING results. */
17211722
if (fmstate->has_returning)
1722-
fmstate->attinmeta = TupleDescGetAttInMetadata(RelationGetDescr(rel));
1723+
fmstate->attinmeta = TupleDescGetAttInMetadata(tupdesc);
17231724

17241725
/* Prepare for output conversion of parameters used in prepared stmt. */
17251726
n_params = list_length(fmstate->target_attrs) + 1;
@@ -1748,7 +1749,7 @@ postgresBeginForeignModify(ModifyTableState *mtstate,
17481749
foreach(lc, fmstate->target_attrs)
17491750
{
17501751
int attnum = lfirst_int(lc);
1751-
Form_pg_attribute attr = RelationGetDescr(rel)->attrs[attnum - 1];
1752+
Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
17521753

17531754
Assert(!attr->attisdropped);
17541755

@@ -5090,9 +5091,10 @@ conversion_error_callback(void *arg)
50905091
{
50915092
/* error occurred in a scan against a foreign table */
50925093
TupleDesc tupdesc = RelationGetDescr(errpos->rel);
5094+
Form_pg_attribute attr = TupleDescAttr(tupdesc, errpos->cur_attno - 1);
50935095

50945096
if (errpos->cur_attno > 0 && errpos->cur_attno <= tupdesc->natts)
5095-
attname = NameStr(tupdesc->attrs[errpos->cur_attno - 1]->attname);
5097+
attname = NameStr(attr->attname);
50965098
else if (errpos->cur_attno == SelfItemPointerAttributeNumber)
50975099
attname = "ctid";
50985100
else if (errpos->cur_attno == ObjectIdAttributeNumber)

contrib/spi/timetravel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ timetravel(PG_FUNCTION_ARGS)
328328
for (i = 1; i <= natts; i++)
329329
{
330330
ctypes[i - 1] = SPI_gettypeid(tupdesc, i);
331-
if (!(tupdesc->attrs[i - 1]->attisdropped)) /* skip dropped columns */
331+
if (!(TupleDescAttr(tupdesc, i - 1)->attisdropped)) /* skip dropped columns */
332332
{
333333
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), "%c$%d", separ, i);
334334
separ = ',';

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