diff options
author | Andres Freund <andres@anarazel.de> | 2017-08-20 11:19:07 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2017-08-20 11:19:07 -0700 |
commit | 2cd70845240087da205695baedab6412342d1dbe (patch) | |
tree | 20a3b6a2231dae248218ac54983c7a854328265f /src/backend/commands | |
parent | b1c2d76a2fcef812af0be3343082414d401909c8 (diff) | |
download | postgresql-2cd70845240087da205695baedab6412342d1dbe.tar.gz postgresql-2cd70845240087da205695baedab6412342d1dbe.zip |
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
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/analyze.c | 2 | ||||
-rw-r--r-- | src/backend/commands/cluster.c | 2 | ||||
-rw-r--r-- | src/backend/commands/copy.c | 56 | ||||
-rw-r--r-- | src/backend/commands/createas.c | 2 | ||||
-rw-r--r-- | src/backend/commands/indexcmds.c | 4 | ||||
-rw-r--r-- | src/backend/commands/matview.c | 3 | ||||
-rw-r--r-- | src/backend/commands/tablecmds.c | 57 | ||||
-rw-r--r-- | src/backend/commands/typecmds.c | 8 | ||||
-rw-r--r-- | src/backend/commands/view.c | 4 |
9 files changed, 80 insertions, 58 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 2b638271b3d..fbad13ea94f 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -871,7 +871,7 @@ compute_index_stats(Relation onerel, double totalrows, static VacAttrStats * examine_attribute(Relation onerel, int attnum, Node *index_expr) { - Form_pg_attribute attr = onerel->rd_att->attrs[attnum - 1]; + Form_pg_attribute attr = TupleDescAttr(onerel->rd_att, attnum - 1); HeapTuple typtuple; VacAttrStats *stats; int i; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index f51f8b94922..48f1e6e2add 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -1714,7 +1714,7 @@ reform_and_rewrite_tuple(HeapTuple tuple, /* Be sure to null out any dropped columns */ for (i = 0; i < newTupDesc->natts; i++) { - if (newTupDesc->attrs[i]->attisdropped) + if (TupleDescAttr(newTupDesc, i)->attisdropped) isnull[i] = true; } diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 375a25fbcf8..cfa3f059c2a 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -1583,12 +1583,13 @@ BeginCopy(ParseState *pstate, foreach(cur, attnums) { int attnum = lfirst_int(cur); + Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1); if (!list_member_int(cstate->attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("FORCE_QUOTE column \"%s\" not referenced by COPY", - NameStr(tupDesc->attrs[attnum - 1]->attname)))); + NameStr(attr->attname)))); cstate->force_quote_flags[attnum - 1] = true; } } @@ -1605,12 +1606,13 @@ BeginCopy(ParseState *pstate, foreach(cur, attnums) { int attnum = lfirst_int(cur); + Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1); if (!list_member_int(cstate->attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("FORCE_NOT_NULL column \"%s\" not referenced by COPY", - NameStr(tupDesc->attrs[attnum - 1]->attname)))); + NameStr(attr->attname)))); cstate->force_notnull_flags[attnum - 1] = true; } } @@ -1627,12 +1629,13 @@ BeginCopy(ParseState *pstate, foreach(cur, attnums) { int attnum = lfirst_int(cur); + Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1); if (!list_member_int(cstate->attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("FORCE_NULL column \"%s\" not referenced by COPY", - NameStr(tupDesc->attrs[attnum - 1]->attname)))); + NameStr(attr->attname)))); cstate->force_null_flags[attnum - 1] = true; } } @@ -1650,12 +1653,13 @@ BeginCopy(ParseState *pstate, foreach(cur, attnums) { int attnum = lfirst_int(cur); + Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1); if (!list_member_int(cstate->attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg_internal("selected column \"%s\" not referenced by COPY", - NameStr(tupDesc->attrs[attnum - 1]->attname)))); + NameStr(attr->attname)))); cstate->convert_select_flags[attnum - 1] = true; } } @@ -1919,7 +1923,6 @@ CopyTo(CopyState cstate) { TupleDesc tupDesc; int num_phys_attrs; - Form_pg_attribute *attr; ListCell *cur; uint64 processed; @@ -1927,7 +1930,6 @@ CopyTo(CopyState cstate) tupDesc = RelationGetDescr(cstate->rel); else tupDesc = cstate->queryDesc->tupDesc; - attr = tupDesc->attrs; num_phys_attrs = tupDesc->natts; cstate->null_print_client = cstate->null_print; /* default */ @@ -1941,13 +1943,14 @@ CopyTo(CopyState cstate) int attnum = lfirst_int(cur); Oid out_func_oid; bool isvarlena; + Form_pg_attribute attr = TupleDescAttr(tupDesc, attnum - 1); if (cstate->binary) - getTypeBinaryOutputInfo(attr[attnum - 1]->atttypid, + getTypeBinaryOutputInfo(attr->atttypid, &out_func_oid, &isvarlena); else - getTypeOutputInfo(attr[attnum - 1]->atttypid, + getTypeOutputInfo(attr->atttypid, &out_func_oid, &isvarlena); fmgr_info(out_func_oid, &cstate->out_functions[attnum - 1]); @@ -2004,7 +2007,7 @@ CopyTo(CopyState cstate) CopySendChar(cstate, cstate->delim[0]); hdr_delim = true; - colname = NameStr(attr[attnum - 1]->attname); + colname = NameStr(TupleDescAttr(tupDesc, attnum - 1)->attname); CopyAttributeOutCSV(cstate, colname, false, list_length(cstate->attnumlist) == 1); @@ -2969,7 +2972,6 @@ BeginCopyFrom(ParseState *pstate, CopyState cstate; bool pipe = (filename == NULL); TupleDesc tupDesc; - Form_pg_attribute *attr; AttrNumber num_phys_attrs, num_defaults; FmgrInfo *in_functions; @@ -3004,7 +3006,6 @@ BeginCopyFrom(ParseState *pstate, cstate->range_table = pstate->p_rtable; tupDesc = RelationGetDescr(cstate->rel); - attr = tupDesc->attrs; num_phys_attrs = tupDesc->natts; num_defaults = 0; volatile_defexprs = false; @@ -3022,16 +3023,18 @@ BeginCopyFrom(ParseState *pstate, for (attnum = 1; attnum <= num_phys_attrs; attnum++) { + Form_pg_attribute att = TupleDescAttr(tupDesc, attnum - 1); + /* We don't need info for dropped attributes */ - if (attr[attnum - 1]->attisdropped) + if (att->attisdropped) continue; /* Fetch the input function and typioparam info */ if (cstate->binary) - getTypeBinaryInputInfo(attr[attnum - 1]->atttypid, + getTypeBinaryInputInfo(att->atttypid, &in_func_oid, &typioparams[attnum - 1]); else - getTypeInputInfo(attr[attnum - 1]->atttypid, + getTypeInputInfo(att->atttypid, &in_func_oid, &typioparams[attnum - 1]); fmgr_info(in_func_oid, &in_functions[attnum - 1]); @@ -3273,7 +3276,6 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext, Datum *values, bool *nulls, Oid *tupleOid) { TupleDesc tupDesc; - Form_pg_attribute *attr; AttrNumber num_phys_attrs, attr_count, num_defaults = cstate->num_defaults; @@ -3287,7 +3289,6 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext, ExprState **defexprs = cstate->defexprs; tupDesc = RelationGetDescr(cstate->rel); - attr = tupDesc->attrs; num_phys_attrs = tupDesc->natts; attr_count = list_length(cstate->attnumlist); nfields = file_has_oids ? (attr_count + 1) : attr_count; @@ -3349,12 +3350,13 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext, { int attnum = lfirst_int(cur); int m = attnum - 1; + Form_pg_attribute att = TupleDescAttr(tupDesc, m); if (fieldno >= fldct) ereport(ERROR, (errcode(ERRCODE_BAD_COPY_FILE_FORMAT), errmsg("missing data for column \"%s\"", - NameStr(attr[m]->attname)))); + NameStr(att->attname)))); string = field_strings[fieldno++]; if (cstate->convert_select_flags && @@ -3388,12 +3390,12 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext, } } - cstate->cur_attname = NameStr(attr[m]->attname); + cstate->cur_attname = NameStr(att->attname); cstate->cur_attval = string; values[m] = InputFunctionCall(&in_functions[m], string, typioparams[m], - attr[m]->atttypmod); + att->atttypmod); if (string != NULL) nulls[m] = false; cstate->cur_attname = NULL; @@ -3472,14 +3474,15 @@ NextCopyFrom(CopyState cstate, ExprContext *econtext, { int attnum = lfirst_int(cur); int m = attnum - 1; + Form_pg_attribute att = TupleDescAttr(tupDesc, m); - cstate->cur_attname = NameStr(attr[m]->attname); + cstate->cur_attname = NameStr(att->attname); i++; values[m] = CopyReadBinaryAttribute(cstate, i, &in_functions[m], typioparams[m], - attr[m]->atttypmod, + att->atttypmod, &nulls[m]); cstate->cur_attname = NULL; } @@ -4709,13 +4712,12 @@ CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist) if (attnamelist == NIL) { /* Generate default column list */ - Form_pg_attribute *attr = tupDesc->attrs; int attr_count = tupDesc->natts; int i; for (i = 0; i < attr_count; i++) { - if (attr[i]->attisdropped) + if (TupleDescAttr(tupDesc, i)->attisdropped) continue; attnums = lappend_int(attnums, i + 1); } @@ -4735,11 +4737,13 @@ CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist) attnum = InvalidAttrNumber; for (i = 0; i < tupDesc->natts; i++) { - if (tupDesc->attrs[i]->attisdropped) + Form_pg_attribute att = TupleDescAttr(tupDesc, i); + + if (att->attisdropped) continue; - if (namestrcmp(&(tupDesc->attrs[i]->attname), name) == 0) + if (namestrcmp(&(att->attname), name) == 0) { - attnum = tupDesc->attrs[i]->attnum; + attnum = att->attnum; break; } } diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 97f9c55d6e7..e60210cb24b 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -468,7 +468,7 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) lc = list_head(into->colNames); for (attnum = 0; attnum < typeinfo->natts; attnum++) { - Form_pg_attribute attribute = typeinfo->attrs[attnum]; + Form_pg_attribute attribute = TupleDescAttr(typeinfo, attnum); ColumnDef *col; char *colname; diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 620704ec490..b61aaac2842 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -242,7 +242,7 @@ CheckIndexCompatible(Oid oldId, for (i = 0; i < old_natts; i++) { if (IsPolymorphicType(get_opclass_input_type(classObjectId[i])) && - irel->rd_att->attrs[i]->atttypid != typeObjectId[i]) + TupleDescAttr(irel->rd_att, i)->atttypid != typeObjectId[i]) { ret = false; break; @@ -270,7 +270,7 @@ CheckIndexCompatible(Oid oldId, op_input_types(indexInfo->ii_ExclusionOps[i], &left, &right); if ((IsPolymorphicType(left) || IsPolymorphicType(right)) && - irel->rd_att->attrs[i]->atttypid != typeObjectId[i]) + TupleDescAttr(irel->rd_att, i)->atttypid != typeObjectId[i]) { ret = false; break; diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index 7d57f97442e..d2e0376511a 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -727,6 +727,7 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, for (i = 0; i < numatts; i++) { int attnum = indexStruct->indkey.values[i]; + Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1); Oid type; Oid op; const char *colname; @@ -745,7 +746,7 @@ refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, if (foundUniqueIndex) appendStringInfoString(&querybuf, " AND "); - colname = quote_identifier(NameStr((tupdesc->attrs[attnum - 1])->attname)); + colname = quote_identifier(NameStr(attr->attname)); appendStringInfo(&querybuf, "newdata.%s ", colname); type = attnumTypeId(matviewRel, attnum); op = lookup_type_cache(type, TYPECACHE_EQ_OPR)->eq_opr; diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 83cb4601641..0f08245a677 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -685,8 +685,10 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, foreach(listptr, stmt->tableElts) { ColumnDef *colDef = lfirst(listptr); + Form_pg_attribute attr; attnum++; + attr = TupleDescAttr(descriptor, attnum - 1); if (colDef->raw_default != NULL) { @@ -698,7 +700,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, rawEnt->attnum = attnum; rawEnt->raw_default = colDef->raw_default; rawDefaults = lappend(rawDefaults, rawEnt); - descriptor->attrs[attnum - 1]->atthasdef = true; + attr->atthasdef = true; } else if (colDef->cooked_default != NULL) { @@ -715,11 +717,11 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, cooked->inhcount = 0; /* ditto */ cooked->is_no_inherit = false; cookedDefaults = lappend(cookedDefaults, cooked); - descriptor->attrs[attnum - 1]->atthasdef = true; + attr->atthasdef = true; } if (colDef->identity) - descriptor->attrs[attnum - 1]->attidentity = colDef->identity; + attr->attidentity = colDef->identity; } /* @@ -1833,7 +1835,8 @@ MergeAttributes(List *schema, List *supers, char relpersistence, 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); int exist_attno; ColumnDef *def; @@ -4417,8 +4420,9 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) */ for (i = 0; i < newTupDesc->natts; i++) { - if (newTupDesc->attrs[i]->attnotnull && - !newTupDesc->attrs[i]->attisdropped) + Form_pg_attribute attr = TupleDescAttr(newTupDesc, i); + + if (attr->attnotnull && !attr->attisdropped) notnull_attrs = lappend_int(notnull_attrs, i); } if (notnull_attrs) @@ -4482,7 +4486,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) */ for (i = 0; i < newTupDesc->natts; i++) { - if (newTupDesc->attrs[i]->attisdropped) + if (TupleDescAttr(newTupDesc, i)->attisdropped) dropped_attrs = lappend_int(dropped_attrs, i); } @@ -4556,11 +4560,15 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) int attn = lfirst_int(l); if (heap_attisnull(tuple, attn + 1)) + { + Form_pg_attribute attr = TupleDescAttr(newTupDesc, attn); + ereport(ERROR, (errcode(ERRCODE_NOT_NULL_VIOLATION), errmsg("column \"%s\" contains null values", - NameStr(newTupDesc->attrs[attn]->attname)), + NameStr(attr->attname)), errtablecol(oldrel, attn + 1))); + } } foreach(l, tab->constraints) @@ -4927,7 +4935,7 @@ find_composite_type_dependencies(Oid typeOid, Relation origRelation, continue; rel = relation_open(pg_depend->objid, AccessShareLock); - att = rel->rd_att->attrs[pg_depend->objsubid - 1]; + att = TupleDescAttr(rel->rd_att, pg_depend->objsubid - 1); if (rel->rd_rel->relkind == RELKIND_RELATION || rel->rd_rel->relkind == RELKIND_MATVIEW || @@ -5693,7 +5701,7 @@ ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode) AttrNumber parent_attnum; parent_attnum = get_attnum(parentId, colName); - if (tupDesc->attrs[parent_attnum - 1]->attnotnull) + if (TupleDescAttr(tupDesc, parent_attnum - 1)->attnotnull) ereport(ERROR, (errcode(ERRCODE_INVALID_TABLE_DEFINITION), errmsg("column \"%s\" is marked NOT NULL in parent table", @@ -7286,13 +7294,15 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, CoercionPathType new_pathtype; Oid old_castfunc; Oid new_castfunc; + Form_pg_attribute attr = TupleDescAttr(tab->oldDesc, + fkattnum[i] - 1); /* * Identify coercion pathways from each of the old and new FK-side * column types to the right (foreign) operand type of the pfeqop. * We may assume that pg_constraint.conkey is not changing. */ - old_fktype = tab->oldDesc->attrs[fkattnum[i] - 1]->atttypid; + old_fktype = attr->atttypid; new_fktype = fktype; old_pathtype = findFkeyCast(pfeqop_right, old_fktype, &old_castfunc); @@ -8963,7 +8973,8 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, ColumnDef *def = (ColumnDef *) cmd->def; TypeName *typeName = def->typeName; HeapTuple heapTup; - Form_pg_attribute attTup; + Form_pg_attribute attTup, + attOldTup; AttrNumber attnum; HeapTuple typeTuple; Form_pg_type tform; @@ -8989,10 +9000,11 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, colName, RelationGetRelationName(rel)))); attTup = (Form_pg_attribute) GETSTRUCT(heapTup); attnum = attTup->attnum; + attOldTup = TupleDescAttr(tab->oldDesc, attnum - 1); /* Check for multiple ALTER TYPE on same column --- can't cope */ - if (attTup->atttypid != tab->oldDesc->attrs[attnum - 1]->atttypid || - attTup->atttypmod != tab->oldDesc->attrs[attnum - 1]->atttypmod) + if (attTup->atttypid != attOldTup->atttypid || + attTup->atttypmod != attOldTup->atttypmod) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot alter type of column \"%s\" twice", @@ -11209,7 +11221,8 @@ MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel) for (parent_attno = 1; parent_attno <= parent_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); /* Ignore dropped columns in the parent. */ @@ -11822,7 +11835,7 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode) *table_attname; /* Get the next non-dropped type attribute. */ - type_attr = typeTupleDesc->attrs[type_attno - 1]; + type_attr = TupleDescAttr(typeTupleDesc, type_attno - 1); if (type_attr->attisdropped) continue; type_attname = NameStr(type_attr->attname); @@ -11835,7 +11848,8 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode) (errcode(ERRCODE_DATATYPE_MISMATCH), errmsg("table is missing column \"%s\"", type_attname))); - table_attr = tableTupleDesc->attrs[table_attno++ - 1]; + table_attr = TupleDescAttr(tableTupleDesc, table_attno - 1); + table_attno++; } while (table_attr->attisdropped); table_attname = NameStr(table_attr->attname); @@ -11860,7 +11874,8 @@ ATExecAddOf(Relation rel, const TypeName *ofTypename, LOCKMODE lockmode) /* Any remaining columns at the end of the table had better be dropped. */ for (; table_attno <= tableTupleDesc->natts; table_attno++) { - Form_pg_attribute table_attr = tableTupleDesc->attrs[table_attno - 1]; + Form_pg_attribute table_attr = TupleDescAttr(tableTupleDesc, + table_attno - 1); if (!table_attr->attisdropped) ereport(ERROR, @@ -12147,7 +12162,7 @@ ATExecReplicaIdentity(Relation rel, ReplicaIdentityStmt *stmt, LOCKMODE lockmode errmsg("index \"%s\" cannot be used as replica identity because column %d is a system column", RelationGetRelationName(indexRel), attno))); - attr = rel->rd_att->attrs[attno - 1]; + attr = TupleDescAttr(rel->rd_att, attno - 1); if (!attr->attnotnull) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), @@ -13451,7 +13466,7 @@ PartConstraintImpliedByRelConstraint(Relation scanrel, for (i = 1; i <= natts; i++) { - Form_pg_attribute att = scanrel->rd_att->attrs[i - 1]; + Form_pg_attribute att = TupleDescAttr(scanrel->rd_att, i - 1); if (att->attnotnull && !att->attisdropped) { @@ -13733,7 +13748,7 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd) natts = tupleDesc->natts; for (attno = 1; attno <= natts; attno++) { - Form_pg_attribute attribute = tupleDesc->attrs[attno - 1]; + Form_pg_attribute attribute = TupleDescAttr(tupleDesc, attno - 1); char *attributeName = NameStr(attribute->attname); /* Ignore dropped */ diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 29ac5d569d7..7ed16aeff46 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -2324,6 +2324,7 @@ AlterDomainNotNull(List *names, bool notNull) for (i = 0; i < rtc->natts; i++) { int attnum = rtc->atts[i]; + Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1); if (heap_attisnull(tuple, attnum)) { @@ -2338,7 +2339,7 @@ AlterDomainNotNull(List *names, bool notNull) ereport(ERROR, (errcode(ERRCODE_NOT_NULL_VIOLATION), errmsg("column \"%s\" of table \"%s\" contains null values", - NameStr(tupdesc->attrs[attnum - 1]->attname), + NameStr(attr->attname), RelationGetRelationName(testrel)), errtablecol(testrel, attnum))); } @@ -2722,6 +2723,7 @@ validateDomainConstraint(Oid domainoid, char *ccbin) Datum d; bool isNull; Datum conResult; + Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1); d = heap_getattr(tuple, attnum, tupdesc, &isNull); @@ -2745,7 +2747,7 @@ validateDomainConstraint(Oid domainoid, char *ccbin) ereport(ERROR, (errcode(ERRCODE_CHECK_VIOLATION), errmsg("column \"%s\" of table \"%s\" contains values that violate the new constraint", - NameStr(tupdesc->attrs[attnum - 1]->attname), + NameStr(attr->attname), RelationGetRelationName(testrel)), errtablecol(testrel, attnum))); } @@ -2930,7 +2932,7 @@ get_rels_with_domain(Oid domainOid, LOCKMODE lockmode) */ if (pg_depend->objsubid > RelationGetNumberOfAttributes(rtc->rel)) continue; - pg_att = rtc->rel->rd_att->attrs[pg_depend->objsubid - 1]; + pg_att = TupleDescAttr(rtc->rel->rd_att, pg_depend->objsubid - 1); if (pg_att->attisdropped || pg_att->atttypid != domainOid) continue; diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index f25a5658d68..076e2a3a402 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -283,8 +283,8 @@ checkViewTupleDesc(TupleDesc newdesc, TupleDesc olddesc) for (i = 0; i < olddesc->natts; i++) { - Form_pg_attribute newattr = newdesc->attrs[i]; - Form_pg_attribute oldattr = olddesc->attrs[i]; + Form_pg_attribute newattr = TupleDescAttr(newdesc, i); + Form_pg_attribute oldattr = TupleDescAttr(olddesc, i); /* XXX msg not right, but we don't support DROP COL on view anyway */ if (newattr->attisdropped != oldattr->attisdropped) |