Since the introduction of the CATALOG_VARLEN stuff, the fixed size of
pg_attribute is exactly sizeof(FormData_pg_attribute), so the ancient
mechanism to track the fixed size manually using
ATTRIBUTE_FIXED_PART_SIZE can be removed.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From 299d839f7a384ffa9c7d90c6d0c63f8c50b9984d Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pete...@gmx.net>
Date: Fri, 17 Aug 2018 23:50:35 +0200
Subject: [PATCH] Remove ATTRIBUTE_FIXED_PART_SIZE

Since the introduction of the CATALOG_VARLEN stuff, the fixed size of
pg_attribute is exactly sizeof(FormData_pg_attribute), so the ancient
mechanism to track the fixed size manually using
ATTRIBUTE_FIXED_PART_SIZE can be removed.
---
 src/backend/access/common/tupdesc.c | 12 ++----------
 src/backend/bootstrap/bootstrap.c   | 15 +++++++--------
 src/backend/catalog/index.c         |  4 ++--
 src/backend/commands/analyze.c      |  4 ++--
 src/backend/utils/cache/relcache.c  | 10 +++++-----
 src/include/catalog/pg_attribute.h  |  9 ---------
 6 files changed, 18 insertions(+), 36 deletions(-)

diff --git a/src/backend/access/common/tupdesc.c 
b/src/backend/access/common/tupdesc.c
index b0434b4672..a27edfd2c6 100644
--- a/src/backend/access/common/tupdesc.c
+++ b/src/backend/access/common/tupdesc.c
@@ -54,14 +54,6 @@ CreateTemplateTupleDesc(int natts, bool hasoid)
        /*
         * Allocate enough memory for the tuple descriptor, including the
         * attribute rows.
-        *
-        * Note: the attribute array stride is sizeof(FormData_pg_attribute),
-        * since we declare the array elements as FormData_pg_attribute for
-        * notational convenience.  However, we only guarantee that the first
-        * ATTRIBUTE_FIXED_PART_SIZE bytes of each entry are valid; most code 
that
-        * copies tupdesc entries around copies just that much.  In principle 
that
-        * could be less due to trailing padding, although with the current
-        * definition of pg_attribute there probably isn't any padding.
         */
        desc = (TupleDesc) palloc(offsetof(struct tupleDesc, attrs) +
                                                          natts * 
sizeof(FormData_pg_attribute));
@@ -96,7 +88,7 @@ CreateTupleDesc(int natts, bool hasoid, Form_pg_attribute 
*attrs)
        desc = CreateTemplateTupleDesc(natts, hasoid);
 
        for (i = 0; i < natts; ++i)
-               memcpy(TupleDescAttr(desc, i), attrs[i], 
ATTRIBUTE_FIXED_PART_SIZE);
+               memcpy(TupleDescAttr(desc, i), attrs[i], 
sizeof(FormData_pg_attribute));
 
        return desc;
 }
@@ -283,7 +275,7 @@ TupleDescCopyEntry(TupleDesc dst, AttrNumber dstAttno,
        AssertArg(dstAttno >= 1);
        AssertArg(dstAttno <= dst->natts);
 
-       memcpy(dstAtt, srcAtt, ATTRIBUTE_FIXED_PART_SIZE);
+       memcpy(dstAtt, srcAtt, sizeof(FormData_pg_attribute));
 
        /*
         * Aside from updating the attno, we'd better reset attcacheoff.
diff --git a/src/backend/bootstrap/bootstrap.c 
b/src/backend/bootstrap/bootstrap.c
index cdd71a9bc3..bd0df56b66 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -621,8 +621,7 @@ boot_openrel(char *relname)
        if (boot_reldesc != NULL)
                closerel(NULL);
 
-       elog(DEBUG4, "open relation %s, attrsize %d",
-                relname, (int) ATTRIBUTE_FIXED_PART_SIZE);
+       elog(DEBUG4, "open relation %s", relname);
 
        boot_reldesc = heap_openrv(makeRangeVar(NULL, relname, -1), NoLock);
        numattr = RelationGetNumberOfAttributes(boot_reldesc);
@@ -630,9 +629,9 @@ boot_openrel(char *relname)
        {
                if (attrtypes[i] == NULL)
                        attrtypes[i] = AllocateAttribute();
-               memmove((char *) attrtypes[i],
-                               (char *) TupleDescAttr(boot_reldesc->rd_att, i),
-                               ATTRIBUTE_FIXED_PART_SIZE);
+               memmove(attrtypes[i],
+                               TupleDescAttr(boot_reldesc->rd_att, i),
+                               sizeof(FormData_pg_attribute));
 
                {
                        Form_pg_attribute at = attrtypes[i];
@@ -698,7 +697,7 @@ DefineAttr(char *name, char *type, int attnum, int nullness)
 
        if (attrtypes[attnum] == NULL)
                attrtypes[attnum] = AllocateAttribute();
-       MemSet(attrtypes[attnum], 0, ATTRIBUTE_FIXED_PART_SIZE);
+       MemSet(attrtypes[attnum], 0, sizeof(FormData_pg_attribute));
 
        namestrcpy(&attrtypes[attnum]->attname, name);
        elog(DEBUG4, "column %s %s", NameStr(attrtypes[attnum]->attname), type);
@@ -1033,14 +1032,14 @@ boot_get_type_io_data(Oid typid,
  *             AllocateAttribute
  *
  * Note: bootstrap never sets any per-column ACLs, so we only need
- * ATTRIBUTE_FIXED_PART_SIZE space per attribute.
+ * sizeof(FormData_pg_attribute) space per attribute.
  * ----------------
  */
 static Form_pg_attribute
 AllocateAttribute(void)
 {
        return (Form_pg_attribute)
-               MemoryContextAllocZero(TopMemoryContext, 
ATTRIBUTE_FIXED_PART_SIZE);
+               MemoryContextAllocZero(TopMemoryContext, 
sizeof(FormData_pg_attribute));
 }
 
 /*
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index b256054908..09a6deb54b 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -360,7 +360,7 @@ ConstructTupleDescriptor(Relation heapRelation,
                         * now that we've determined the "from", let's copy the 
tuple desc
                         * data...
                         */
-                       memcpy(to, from, ATTRIBUTE_FIXED_PART_SIZE);
+                       memcpy(to, from, sizeof(FormData_pg_attribute));
 
                        /*
                         * Fix the stuff that should not be the same as the 
underlying
@@ -384,7 +384,7 @@ ConstructTupleDescriptor(Relation heapRelation,
                        /* Expressional index */
                        Node       *indexkey;
 
-                       MemSet(to, 0, ATTRIBUTE_FIXED_PART_SIZE);
+                       MemSet(to, 0, sizeof(FormData_pg_attribute));
 
                        if (indexpr_item == NULL)       /* shouldn't happen */
                                elog(ERROR, "too few entries in indexprs list");
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index 3e148f03d0..1e6150c670 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -940,8 +940,8 @@ examine_attribute(Relation onerel, int attnum, Node 
*index_expr)
         * fixed fields of the pg_attribute tuple.
         */
        stats = (VacAttrStats *) palloc0(sizeof(VacAttrStats));
-       stats->attr = (Form_pg_attribute) palloc(ATTRIBUTE_FIXED_PART_SIZE);
-       memcpy(stats->attr, attr, ATTRIBUTE_FIXED_PART_SIZE);
+       stats->attr = (Form_pg_attribute) palloc(sizeof(FormData_pg_attribute));
+       memcpy(stats->attr, attr, sizeof(FormData_pg_attribute));
 
        /*
         * When analyzing an expression index, believe the expression tree's 
type
diff --git a/src/backend/utils/cache/relcache.c 
b/src/backend/utils/cache/relcache.c
index 6125421d39..e7fa3ea1bc 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -557,7 +557,7 @@ RelationBuildTupleDesc(Relation relation)
 
                memcpy(TupleDescAttr(relation->rd_att, attnum - 1),
                           attp,
-                          ATTRIBUTE_FIXED_PART_SIZE);
+                          sizeof(FormData_pg_attribute));
 
                /* Update constraint/default info */
                if (attp->attnotnull)
@@ -1813,7 +1813,7 @@ formrdesc(const char *relationName, Oid relationReltype,
        {
                memcpy(TupleDescAttr(relation->rd_att, i),
                           &attrs[i],
-                          ATTRIBUTE_FIXED_PART_SIZE);
+                          sizeof(FormData_pg_attribute));
                has_not_null |= attrs[i].attnotnull;
                /* make sure attcacheoff is valid */
                TupleDescAttr(relation->rd_att, i)->attcacheoff = -1;
@@ -3883,7 +3883,7 @@ BuildHardcodedDescriptor(int natts, const 
FormData_pg_attribute *attrs,
 
        for (i = 0; i < natts; i++)
        {
-               memcpy(TupleDescAttr(result, i), &attrs[i], 
ATTRIBUTE_FIXED_PART_SIZE);
+               memcpy(TupleDescAttr(result, i), &attrs[i], 
sizeof(FormData_pg_attribute));
                /* make sure attcacheoff is valid */
                TupleDescAttr(result, i)->attcacheoff = -1;
        }
@@ -5478,7 +5478,7 @@ load_relcache_init_file(bool shared)
 
                        if (fread(&len, 1, sizeof(len), fp) != sizeof(len))
                                goto read_failed;
-                       if (len != ATTRIBUTE_FIXED_PART_SIZE)
+                       if (len != sizeof(FormData_pg_attribute))
                                goto read_failed;
                        if (fread(attr, 1, len, fp) != len)
                                goto read_failed;
@@ -5872,7 +5872,7 @@ write_relcache_init_file(bool shared)
                for (i = 0; i < relform->relnatts; i++)
                {
                        write_item(TupleDescAttr(rel->rd_att, i),
-                                          ATTRIBUTE_FIXED_PART_SIZE, fp);
+                                          sizeof(FormData_pg_attribute), fp);
                }
 
                /* next, do the access method specific field */
diff --git a/src/include/catalog/pg_attribute.h 
b/src/include/catalog/pg_attribute.h
index dc36753ede..df1a17d2a5 100644
--- a/src/include/catalog/pg_attribute.h
+++ b/src/include/catalog/pg_attribute.h
@@ -180,15 +180,6 @@ CATALOG(pg_attribute,1249,AttributeRelationId) 
BKI_BOOTSTRAP BKI_WITHOUT_OIDS BK
 #endif
 } FormData_pg_attribute;
 
-/*
- * ATTRIBUTE_FIXED_PART_SIZE is the size of the fixed-layout,
- * guaranteed-not-null part of a pg_attribute row.  This is in fact as much
- * of the row as gets copied into tuple descriptors, so don't expect you
- * can access fields beyond attcollation except in a real tuple!
- */
-#define ATTRIBUTE_FIXED_PART_SIZE \
-       (offsetof(FormData_pg_attribute,attcollation) + sizeof(Oid))
-
 /* ----------------
  *             Form_pg_attribute corresponds to a pointer to a tuple with
  *             the format of pg_attribute relation.
-- 
2.18.0

Reply via email to