Skip to content

Commit e263f6a

Browse files
committed
Introduce TupleDescAttr macro for future compability with pg11
1 parent eecab83 commit e263f6a

7 files changed

+22
-23
lines changed

src/compat/pg_compat.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ get_rel_persistence(Oid relid)
520520
}
521521
#endif
522522

523+
#if PG_VERSION_NUM < 110000
524+
#define TupleDescAttr(tupdesc, i) ((tupdesc)->attrs[(i)])
525+
#endif
523526

524527
#if (PG_VERSION_NUM >= 90500 && PG_VERSION_NUM <= 90505) || \
525528
(PG_VERSION_NUM >= 90600 && PG_VERSION_NUM <= 90601)
@@ -542,7 +545,7 @@ convert_tuples_by_name_map(TupleDesc indesc,
542545
attrMap = (AttrNumber *) palloc0(n * sizeof(AttrNumber));
543546
for (i = 0; i < n; i++)
544547
{
545-
Form_pg_attribute att = outdesc->attrs[i];
548+
Form_pg_attribute att = TupleDescAttr(outdesc, i);
546549
char *attname;
547550
Oid atttypid;
548551
int32 atttypmod;
@@ -555,7 +558,7 @@ convert_tuples_by_name_map(TupleDesc indesc,
555558
atttypmod = att->atttypmod;
556559
for (j = 0; j < indesc->natts; j++)
557560
{
558-
att = indesc->attrs[j];
561+
att = TupleDescAttr(indesc, j);
559562
if (att->attisdropped)
560563
continue;
561564
if (strcmp(attname, NameStr(att->attname)) == 0)
@@ -587,8 +590,6 @@ convert_tuples_by_name_map(TupleDesc indesc,
587590
}
588591
#endif
589592

590-
591-
592593
/*
593594
* -------------
594595
* Common code

src/init.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,8 @@ pathman_config_contains_relation(Oid relid, Datum *values, bool *isnull,
631631
rel = heap_open(get_pathman_config_relid(false), AccessShareLock);
632632

633633
/* Check that 'partrel' column is of regclass type */
634-
Assert(RelationGetDescr(rel)->
635-
attrs[Anum_pathman_config_partrel - 1]->
636-
atttypid == REGCLASSOID);
634+
Assert(TupleDescAttr(RelationGetDescr(rel),
635+
Anum_pathman_config_partrel - 1)->atttypid == REGCLASSOID);
637636

638637
/* Check that number of columns == Natts_pathman_config */
639638
Assert(RelationGetDescr(rel)->natts == Natts_pathman_config);
@@ -880,9 +879,8 @@ read_pathman_config(void (*per_row_cb)(Datum *values,
880879
rel = heap_open(get_pathman_config_relid(false), AccessShareLock);
881880

882881
/* Check that 'partrel' column is if regclass type */
883-
Assert(RelationGetDescr(rel)->
884-
attrs[Anum_pathman_config_partrel - 1]->
885-
atttypid == REGCLASSOID);
882+
Assert(TupleDescAttr(RelationGetDescr(rel),
883+
Anum_pathman_config_partrel - 1)->atttypid == REGCLASSOID);
886884

887885
/* Check that number of columns == Natts_pathman_config */
888886
Assert(RelationGetDescr(rel)->natts == Natts_pathman_config);

src/partition_creation.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -920,8 +920,7 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
920920
{
921921
Form_pg_attribute acl_column;
922922

923-
acl_column = pg_class_desc->attrs[Anum_pg_class_relacl - 1];
924-
923+
acl_column = TupleDescAttr(pg_class_desc, Anum_pg_class_relacl - 1);
925924
acl_datum = datumCopy(acl_datum, acl_column->attbyval, acl_column->attlen);
926925
}
927926

@@ -997,7 +996,7 @@ postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)
997996
{
998997
Form_pg_attribute acl_column;
999998

1000-
acl_column = pg_attribute_desc->attrs[Anum_pg_attribute_attacl - 1];
999+
acl_column = TupleDescAttr(pg_attribute_desc, Anum_pg_attribute_attacl - 1);
10011000

10021001
acl_datum = datumCopy(acl_datum,
10031002
acl_column->attbyval,

src/partition_filter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ prepare_rri_fdw_for_insert(EState *estate,
10221022
TargetEntry *te;
10231023
Param *param;
10241024

1025-
attr = tupdesc->attrs[i];
1025+
attr = TupleDescAttr(tupdesc, i);
10261026

10271027
if (attr->attisdropped)
10281028
continue;

src/pg_pathman.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
17871787
Oid attcollation;
17881788
int new_attno;
17891789

1790-
att = old_tupdesc->attrs[old_attno];
1790+
att = TupleDescAttr(old_tupdesc, old_attno);
17911791
if (att->attisdropped)
17921792
{
17931793
/* Just put NULL into this list entry */
@@ -1825,15 +1825,15 @@ make_inh_translation_list(Relation oldrelation, Relation newrelation,
18251825
* notational device to include the assignment into the if-clause.
18261826
*/
18271827
if (old_attno < newnatts &&
1828-
(att = new_tupdesc->attrs[old_attno]) != NULL &&
1828+
(att = TupleDescAttr(new_tupdesc, old_attno)) != NULL &&
18291829
!att->attisdropped && att->attinhcount != 0 &&
18301830
strcmp(attname, NameStr(att->attname)) == 0)
18311831
new_attno = old_attno;
18321832
else
18331833
{
18341834
for (new_attno = 0; new_attno < newnatts; new_attno++)
18351835
{
1836-
att = new_tupdesc->attrs[new_attno];
1836+
att = TupleDescAttr(new_tupdesc, new_attno);
18371837

18381838
/*
18391839
* Make clang analyzer happy:

src/relation_info.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ PrelExpressionAttributesMap(const PartRelationInfo *prel,
14781478

14791479
for (j = 0; j < source_natts; j++)
14801480
{
1481-
Form_pg_attribute att = source_tupdesc->attrs[j];
1481+
Form_pg_attribute att = TupleDescAttr(source_tupdesc, j);
14821482

14831483
if (att->attisdropped)
14841484
continue; /* attrMap[attnum - 1] is already 0 */

src/utility_stmt_hooking.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,12 @@ CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
262262
if (attnamelist == NIL)
263263
{
264264
/* Generate default column list */
265-
Form_pg_attribute *attr = tupDesc->attrs;
266265
int attr_count = tupDesc->natts;
267266
int i;
268267

269268
for (i = 0; i < attr_count; i++)
270269
{
271-
if (attr[i]->attisdropped)
270+
if (TupleDescAttr(tupDesc, i)->attisdropped)
272271
continue;
273272
attnums = lappend_int(attnums, i + 1);
274273
}
@@ -288,11 +287,13 @@ CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
288287
attnum = InvalidAttrNumber;
289288
for (i = 0; i < tupDesc->natts; i++)
290289
{
291-
if (tupDesc->attrs[i]->attisdropped)
290+
Form_pg_attribute att = TupleDescAttr(tupDesc, i);
291+
292+
if (att->attisdropped)
292293
continue;
293-
if (namestrcmp(&(tupDesc->attrs[i]->attname), name) == 0)
294+
if (namestrcmp(&(att->attname), name) == 0)
294295
{
295-
attnum = tupDesc->attrs[i]->attnum;
296+
attnum = att->attnum;
296297
break;
297298
}
298299
}

0 commit comments

Comments
 (0)