Remove direct access to tupleDesc->attrs

A level of indirection was removed from this field for PostgreSQL 11.
By using the handy provided macro, we can be version agnostic.
pull/1633/head
Jason Petersen 2017-08-31 16:06:50 -06:00
parent 6a020b5adc
commit fbeaa2f9d0
No known key found for this signature in database
GPG Key ID: 9F1D3510D110ABA9
6 changed files with 16 additions and 15 deletions

View File

@ -1284,7 +1284,7 @@ TupleDescColumnNameList(TupleDesc tupleDescriptor)
for (columnIndex = 0; columnIndex < tupleDescriptor->natts; columnIndex++) for (columnIndex = 0; columnIndex < tupleDescriptor->natts; columnIndex++)
{ {
Form_pg_attribute currentColumn = tupleDescriptor->attrs[columnIndex]; Form_pg_attribute currentColumn = TupleDescAttr(tupleDescriptor, columnIndex);
char *columnName = NameStr(currentColumn->attname); char *columnName = NameStr(currentColumn->attname);
if (currentColumn->attisdropped) if (currentColumn->attisdropped)
@ -1311,7 +1311,7 @@ RelationUsesIdentityColumns(TupleDesc relationDesc)
for (attributeIndex = 0; attributeIndex < relationDesc->natts; attributeIndex++) for (attributeIndex = 0; attributeIndex < relationDesc->natts; attributeIndex++)
{ {
Form_pg_attribute attributeForm = relationDesc->attrs[attributeIndex]; Form_pg_attribute attributeForm = TupleDescAttr(relationDesc, attributeIndex);
if (attributeForm->attidentity != '\0') if (attributeForm->attidentity != '\0')
{ {

View File

@ -334,7 +334,7 @@ CopyToExistingShards(CopyStmt *copyStatement, char *completionTag)
/* build the list of column names for remote COPY statements */ /* build the list of column names for remote COPY statements */
for (columnIndex = 0; columnIndex < columnCount; columnIndex++) for (columnIndex = 0; columnIndex < columnCount; columnIndex++)
{ {
Form_pg_attribute currentColumn = tupleDescriptor->attrs[columnIndex]; Form_pg_attribute currentColumn = TupleDescAttr(tupleDescriptor, columnIndex);
char *columnName = NameStr(currentColumn->attname); char *columnName = NameStr(currentColumn->attname);
if (currentColumn->attisdropped) if (currentColumn->attisdropped)
@ -892,7 +892,7 @@ CanUseBinaryCopyFormat(TupleDesc tupleDescription)
for (columnIndex = 0; columnIndex < totalColumnCount; columnIndex++) for (columnIndex = 0; columnIndex < totalColumnCount; columnIndex++)
{ {
Form_pg_attribute currentColumn = tupleDescription->attrs[columnIndex]; Form_pg_attribute currentColumn = TupleDescAttr(tupleDescription, columnIndex);
Oid typeId = InvalidOid; Oid typeId = InvalidOid;
char typeCategory = '\0'; char typeCategory = '\0';
bool typePreferred = false; bool typePreferred = false;
@ -1231,7 +1231,7 @@ ColumnOutputFunctions(TupleDesc rowDescriptor, bool binaryFormat)
for (columnIndex = 0; columnIndex < columnCount; columnIndex++) for (columnIndex = 0; columnIndex < columnCount; columnIndex++)
{ {
FmgrInfo *currentOutputFunction = &columnOutputFunctions[columnIndex]; FmgrInfo *currentOutputFunction = &columnOutputFunctions[columnIndex];
Form_pg_attribute currentColumn = rowDescriptor->attrs[columnIndex]; Form_pg_attribute currentColumn = TupleDescAttr(rowDescriptor, columnIndex);
Oid columnTypeId = currentColumn->atttypid; Oid columnTypeId = currentColumn->atttypid;
Oid outputFunctionId = InvalidOid; Oid outputFunctionId = InvalidOid;
bool typeVariableLength = false; bool typeVariableLength = false;
@ -1282,7 +1282,7 @@ AppendCopyRowData(Datum *valueArray, bool *isNullArray, TupleDesc rowDescriptor,
} }
for (columnIndex = 0; columnIndex < totalColumnCount; columnIndex++) for (columnIndex = 0; columnIndex < totalColumnCount; columnIndex++)
{ {
Form_pg_attribute currentColumn = rowDescriptor->attrs[columnIndex]; Form_pg_attribute currentColumn = TupleDescAttr(rowDescriptor, columnIndex);
Datum value = valueArray[columnIndex]; Datum value = valueArray[columnIndex];
bool isNull = isNullArray[columnIndex]; bool isNull = isNullArray[columnIndex];
bool lastColumn = false; bool lastColumn = false;
@ -1357,7 +1357,7 @@ AvailableColumnCount(TupleDesc tupleDescriptor)
for (columnIndex = 0; columnIndex < tupleDescriptor->natts; columnIndex++) for (columnIndex = 0; columnIndex < tupleDescriptor->natts; columnIndex++)
{ {
Form_pg_attribute currentColumn = tupleDescriptor->attrs[columnIndex]; Form_pg_attribute currentColumn = TupleDescAttr(tupleDescriptor, columnIndex);
if (!currentColumn->attisdropped) if (!currentColumn->attisdropped)
{ {

View File

@ -108,10 +108,10 @@ master_run_on_worker(PG_FUNCTION_ARGS)
* Check to make sure we have correct tuple descriptor * Check to make sure we have correct tuple descriptor
*/ */
if (tupleDescriptor->natts != 4 || if (tupleDescriptor->natts != 4 ||
tupleDescriptor->attrs[0]->atttypid != TEXTOID || TupleDescAttr(tupleDescriptor, 0)->atttypid != TEXTOID ||
tupleDescriptor->attrs[1]->atttypid != INT4OID || TupleDescAttr(tupleDescriptor, 1)->atttypid != INT4OID ||
tupleDescriptor->attrs[2]->atttypid != BOOLOID || TupleDescAttr(tupleDescriptor, 2)->atttypid != BOOLOID ||
tupleDescriptor->attrs[3]->atttypid != TEXTOID) TupleDescAttr(tupleDescriptor, 3)->atttypid != TEXTOID)
{ {
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_INVALID_COLUMN_DEFINITION), (errcode(ERRCODE_INVALID_COLUMN_DEFINITION),

View File

@ -984,7 +984,7 @@ TypeOfColumn(Oid tableId, int16 columnId)
{ {
Relation tableRelation = relation_open(tableId, NoLock); Relation tableRelation = relation_open(tableId, NoLock);
TupleDesc tupleDescriptor = RelationGetDescr(tableRelation); TupleDesc tupleDescriptor = RelationGetDescr(tableRelation);
Form_pg_attribute attrForm = tupleDescriptor->attrs[columnId - 1]; Form_pg_attribute attrForm = TupleDescAttr(tupleDescriptor, columnId - 1);
relation_close(tableRelation, NoLock); relation_close(tableRelation, NoLock);
return attrForm->atttypid; return attrForm->atttypid;
} }

View File

@ -262,7 +262,8 @@ ConvertRteToSubqueryWithEmptyResult(RangeTblEntry *rte)
for (columnIndex = 0; columnIndex < columnCount; columnIndex++) for (columnIndex = 0; columnIndex < columnCount; columnIndex++)
{ {
FormData_pg_attribute *attributeForm = tupleDescriptor->attrs[columnIndex]; FormData_pg_attribute *attributeForm = TupleDescAttr(tupleDescriptor,
columnIndex);
TargetEntry *targetEntry = NULL; TargetEntry *targetEntry = NULL;
StringInfo resname = NULL; StringInfo resname = NULL;
Const *constValue = NULL; Const *constValue = NULL;

View File

@ -333,7 +333,7 @@ pg_get_tableschemadef_string(Oid tableRelationId, bool includeSequenceDefaults)
for (attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++) for (attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++)
{ {
Form_pg_attribute attributeForm = tupleDescriptor->attrs[attributeIndex]; Form_pg_attribute attributeForm = TupleDescAttr(tupleDescriptor, attributeIndex);
/* /*
* We disregard the inherited attributes (i.e., attinhcount > 0) here. The * We disregard the inherited attributes (i.e., attinhcount > 0) here. The
@ -545,7 +545,7 @@ pg_get_tablecolumnoptionsdef_string(Oid tableRelationId)
for (attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++) for (attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++)
{ {
Form_pg_attribute attributeForm = tupleDescriptor->attrs[attributeIndex]; Form_pg_attribute attributeForm = TupleDescAttr(tupleDescriptor, attributeIndex);
char *attributeName = NameStr(attributeForm->attname); char *attributeName = NameStr(attributeForm->attname);
char defaultStorageType = get_typstorage(attributeForm->atttypid); char defaultStorageType = get_typstorage(attributeForm->atttypid);