mirror of
https://github.com/postgres/postgres.git
synced 2025-10-28 11:55:03 +03:00
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
This commit is contained in:
@@ -1050,7 +1050,7 @@ transformOnConflictClause(ParseState *pstate,
|
||||
*/
|
||||
for (attno = 0; attno < targetrel->rd_rel->relnatts; attno++)
|
||||
{
|
||||
Form_pg_attribute attr = targetrel->rd_att->attrs[attno];
|
||||
Form_pg_attribute attr = TupleDescAttr(targetrel->rd_att, attno);
|
||||
char *name;
|
||||
|
||||
if (attr->attisdropped)
|
||||
|
||||
@@ -982,9 +982,10 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
Node *expr;
|
||||
Node *cexpr;
|
||||
Oid exprtype;
|
||||
Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
|
||||
|
||||
/* Fill in NULLs for dropped columns in rowtype */
|
||||
if (tupdesc->attrs[i]->attisdropped)
|
||||
if (attr->attisdropped)
|
||||
{
|
||||
/*
|
||||
* can't use atttypid here, but it doesn't really matter what type
|
||||
@@ -1008,8 +1009,8 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
|
||||
cexpr = coerce_to_target_type(pstate,
|
||||
expr, exprtype,
|
||||
tupdesc->attrs[i]->atttypid,
|
||||
tupdesc->attrs[i]->atttypmod,
|
||||
attr->atttypid,
|
||||
attr->atttypmod,
|
||||
ccontext,
|
||||
COERCE_IMPLICIT_CAST,
|
||||
-1);
|
||||
@@ -1021,7 +1022,7 @@ coerce_record_to_complex(ParseState *pstate, Node *node,
|
||||
format_type_be(targetTypeId)),
|
||||
errdetail("Cannot cast type %s to %s in column %d.",
|
||||
format_type_be(exprtype),
|
||||
format_type_be(tupdesc->attrs[i]->atttypid),
|
||||
format_type_be(attr->atttypid),
|
||||
ucolno),
|
||||
parser_coercion_errposition(pstate, location, expr)));
|
||||
newargs = lappend(newargs, cexpr);
|
||||
|
||||
@@ -1834,7 +1834,7 @@ ParseComplexProjection(ParseState *pstate, char *funcname, Node *first_arg,
|
||||
|
||||
for (i = 0; i < tupdesc->natts; i++)
|
||||
{
|
||||
Form_pg_attribute att = tupdesc->attrs[i];
|
||||
Form_pg_attribute att = TupleDescAttr(tupdesc, i);
|
||||
|
||||
if (strcmp(funcname, NameStr(att->attname)) == 0 &&
|
||||
!att->attisdropped)
|
||||
|
||||
@@ -1052,7 +1052,7 @@ buildRelationAliases(TupleDesc tupdesc, Alias *alias, Alias *eref)
|
||||
|
||||
for (varattno = 0; varattno < maxattrs; varattno++)
|
||||
{
|
||||
Form_pg_attribute attr = tupdesc->attrs[varattno];
|
||||
Form_pg_attribute attr = TupleDescAttr(tupdesc, varattno);
|
||||
Value *attrname;
|
||||
|
||||
if (attr->attisdropped)
|
||||
@@ -2026,19 +2026,18 @@ addRangeTableEntryForENR(ParseState *pstate,
|
||||
rte->colcollations = NIL;
|
||||
for (attno = 1; attno <= tupdesc->natts; ++attno)
|
||||
{
|
||||
if (tupdesc->attrs[attno - 1]->atttypid == InvalidOid &&
|
||||
!(tupdesc->attrs[attno - 1]->attisdropped))
|
||||
Form_pg_attribute att = TupleDescAttr(tupdesc, attno - 1);
|
||||
|
||||
if (att->atttypid == InvalidOid &&
|
||||
!(att->attisdropped))
|
||||
elog(ERROR, "atttypid was invalid for column which has not been dropped from \"%s\"",
|
||||
rv->relname);
|
||||
rte->coltypes =
|
||||
lappend_oid(rte->coltypes,
|
||||
tupdesc->attrs[attno - 1]->atttypid);
|
||||
lappend_oid(rte->coltypes, att->atttypid);
|
||||
rte->coltypmods =
|
||||
lappend_int(rte->coltypmods,
|
||||
tupdesc->attrs[attno - 1]->atttypmod);
|
||||
lappend_int(rte->coltypmods, att->atttypmod);
|
||||
rte->colcollations =
|
||||
lappend_oid(rte->colcollations,
|
||||
tupdesc->attrs[attno - 1]->attcollation);
|
||||
lappend_oid(rte->colcollations, att->attcollation);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2514,7 +2513,7 @@ expandTupleDesc(TupleDesc tupdesc, Alias *eref, int count, int offset,
|
||||
Assert(count <= tupdesc->natts);
|
||||
for (varattno = 0; varattno < count; varattno++)
|
||||
{
|
||||
Form_pg_attribute attr = tupdesc->attrs[varattno];
|
||||
Form_pg_attribute attr = TupleDescAttr(tupdesc, varattno);
|
||||
|
||||
if (attr->attisdropped)
|
||||
{
|
||||
@@ -2749,7 +2748,7 @@ get_rte_attribute_type(RangeTblEntry *rte, AttrNumber attnum,
|
||||
|
||||
Assert(tupdesc);
|
||||
Assert(attnum <= tupdesc->natts);
|
||||
att_tup = tupdesc->attrs[attnum - 1];
|
||||
att_tup = TupleDescAttr(tupdesc, attnum - 1);
|
||||
|
||||
/*
|
||||
* If dropped column, pretend it ain't there. See
|
||||
@@ -2953,7 +2952,8 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
|
||||
|
||||
Assert(tupdesc);
|
||||
Assert(attnum - atts_done <= tupdesc->natts);
|
||||
att_tup = tupdesc->attrs[attnum - atts_done - 1];
|
||||
att_tup = TupleDescAttr(tupdesc,
|
||||
attnum - atts_done - 1);
|
||||
return att_tup->attisdropped;
|
||||
}
|
||||
/* Otherwise, it can't have any dropped columns */
|
||||
@@ -3042,7 +3042,7 @@ attnameAttNum(Relation rd, const char *attname, bool sysColOK)
|
||||
|
||||
for (i = 0; i < rd->rd_rel->relnatts; i++)
|
||||
{
|
||||
Form_pg_attribute att = rd->rd_att->attrs[i];
|
||||
Form_pg_attribute att = TupleDescAttr(rd->rd_att, i);
|
||||
|
||||
if (namestrcmp(&(att->attname), attname) == 0 && !att->attisdropped)
|
||||
return i + 1;
|
||||
@@ -3102,7 +3102,7 @@ attnumAttName(Relation rd, int attid)
|
||||
}
|
||||
if (attid > rd->rd_att->natts)
|
||||
elog(ERROR, "invalid attribute number %d", attid);
|
||||
return &rd->rd_att->attrs[attid - 1]->attname;
|
||||
return &TupleDescAttr(rd->rd_att, attid - 1)->attname;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3124,7 +3124,7 @@ attnumTypeId(Relation rd, int attid)
|
||||
}
|
||||
if (attid > rd->rd_att->natts)
|
||||
elog(ERROR, "invalid attribute number %d", attid);
|
||||
return rd->rd_att->attrs[attid - 1]->atttypid;
|
||||
return TupleDescAttr(rd->rd_att, attid - 1)->atttypid;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3142,7 +3142,7 @@ attnumCollationId(Relation rd, int attid)
|
||||
}
|
||||
if (attid > rd->rd_att->natts)
|
||||
elog(ERROR, "invalid attribute number %d", attid);
|
||||
return rd->rd_att->attrs[attid - 1]->attcollation;
|
||||
return TupleDescAttr(rd->rd_att, attid - 1)->attcollation;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -484,8 +484,8 @@ transformAssignedExpr(ParseState *pstate,
|
||||
colname),
|
||||
parser_errposition(pstate, location)));
|
||||
attrtype = attnumTypeId(rd, attrno);
|
||||
attrtypmod = rd->rd_att->attrs[attrno - 1]->atttypmod;
|
||||
attrcollation = rd->rd_att->attrs[attrno - 1]->attcollation;
|
||||
attrtypmod = TupleDescAttr(rd->rd_att, attrno - 1)->atttypmod;
|
||||
attrcollation = TupleDescAttr(rd->rd_att, attrno - 1)->attcollation;
|
||||
|
||||
/*
|
||||
* If the expression is a DEFAULT placeholder, insert the attribute's
|
||||
@@ -959,19 +959,21 @@ checkInsertTargets(ParseState *pstate, List *cols, List **attrnos)
|
||||
/*
|
||||
* Generate default column list for INSERT.
|
||||
*/
|
||||
Form_pg_attribute *attr = pstate->p_target_relation->rd_att->attrs;
|
||||
int numcol = pstate->p_target_relation->rd_rel->relnatts;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < numcol; i++)
|
||||
{
|
||||
ResTarget *col;
|
||||
Form_pg_attribute attr;
|
||||
|
||||
if (attr[i]->attisdropped)
|
||||
attr = TupleDescAttr(pstate->p_target_relation->rd_att, i);
|
||||
|
||||
if (attr->attisdropped)
|
||||
continue;
|
||||
|
||||
col = makeNode(ResTarget);
|
||||
col->name = pstrdup(NameStr(attr[i]->attname));
|
||||
col->name = pstrdup(NameStr(attr->attname));
|
||||
col->indirection = NIL;
|
||||
col->val = NULL;
|
||||
col->location = -1;
|
||||
@@ -1407,7 +1409,7 @@ ExpandRowReference(ParseState *pstate, Node *expr,
|
||||
numAttrs = tupleDesc->natts;
|
||||
for (i = 0; i < numAttrs; i++)
|
||||
{
|
||||
Form_pg_attribute att = tupleDesc->attrs[i];
|
||||
Form_pg_attribute att = TupleDescAttr(tupleDesc, i);
|
||||
FieldSelect *fselect;
|
||||
|
||||
if (att->attisdropped)
|
||||
|
||||
@@ -969,7 +969,8 @@ transformTableLikeClause(CreateStmtContext *cxt, TableLikeClause *table_like_cla
|
||||
for (parent_attno = 1; parent_attno <= tupleDesc->natts;
|
||||
parent_attno++)
|
||||
{
|
||||
Form_pg_attribute attribute = tupleDesc->attrs[parent_attno - 1];
|
||||
Form_pg_attribute attribute = TupleDescAttr(tupleDesc,
|
||||
parent_attno - 1);
|
||||
char *attributeName = NameStr(attribute->attname);
|
||||
ColumnDef *def;
|
||||
|
||||
@@ -1219,7 +1220,7 @@ transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
|
||||
tupdesc = lookup_rowtype_tupdesc(ofTypeId, -1);
|
||||
for (i = 0; i < tupdesc->natts; i++)
|
||||
{
|
||||
Form_pg_attribute attr = tupdesc->attrs[i];
|
||||
Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
|
||||
ColumnDef *n;
|
||||
|
||||
if (attr->attisdropped)
|
||||
@@ -1256,7 +1257,6 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
|
||||
const AttrNumber *attmap, int attmap_length)
|
||||
{
|
||||
Oid source_relid = RelationGetRelid(source_idx);
|
||||
Form_pg_attribute *attrs = RelationGetDescr(source_idx)->attrs;
|
||||
HeapTuple ht_idxrel;
|
||||
HeapTuple ht_idx;
|
||||
HeapTuple ht_am;
|
||||
@@ -1434,6 +1434,8 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
|
||||
{
|
||||
IndexElem *iparam;
|
||||
AttrNumber attnum = idxrec->indkey.values[keyno];
|
||||
Form_pg_attribute attr = TupleDescAttr(RelationGetDescr(source_idx),
|
||||
keyno);
|
||||
int16 opt = source_idx->rd_indoption[keyno];
|
||||
|
||||
iparam = makeNode(IndexElem);
|
||||
@@ -1481,7 +1483,7 @@ generateClonedIndexStmt(CreateStmtContext *cxt, Relation source_idx,
|
||||
}
|
||||
|
||||
/* Copy the original index column name */
|
||||
iparam->indexcolname = pstrdup(NameStr(attrs[keyno]->attname));
|
||||
iparam->indexcolname = pstrdup(NameStr(attr->attname));
|
||||
|
||||
/* Add the collation name, if non-default */
|
||||
iparam->collation = get_collation(indcollation->values[keyno], keycoltype);
|
||||
@@ -1921,7 +1923,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
if (attnum > 0)
|
||||
{
|
||||
Assert(attnum <= heap_rel->rd_att->natts);
|
||||
attform = heap_rel->rd_att->attrs[attnum - 1];
|
||||
attform = TupleDescAttr(heap_rel->rd_att, attnum - 1);
|
||||
}
|
||||
else
|
||||
attform = SystemAttributeDefinition(attnum,
|
||||
@@ -2040,7 +2042,8 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
inh->relname)));
|
||||
for (count = 0; count < rel->rd_att->natts; count++)
|
||||
{
|
||||
Form_pg_attribute inhattr = rel->rd_att->attrs[count];
|
||||
Form_pg_attribute inhattr = TupleDescAttr(rel->rd_att,
|
||||
count);
|
||||
char *inhname = NameStr(inhattr->attname);
|
||||
|
||||
if (inhattr->attisdropped)
|
||||
|
||||
Reference in New Issue
Block a user