From 90189eefc1e11822794e3386d9bafafd3ba3a6e8 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 28 Mar 2023 09:58:14 +0200 Subject: Save a few bytes in pg_attribute Change the columns attndims, attstattarget, and attinhcount from int32 to int16, and reorder a bit. This saves some space (currently 4 bytes) in pg_attribute and tuple descriptors, which translates into small performance benefits and/or room for new columns in pg_attribute needed by future features. attndims and attinhcount are never realistically used with values larger than int16. Just to be sure, add some overflow checks. attstattarget is currently limited explicitly to 10000. For consistency, pg_constraint.coninhcount is also changed like attinhcount. Discussion: https://www.postgresql.org/message-id/flat/d07ffc2b-e0e8-77f7-38fb-be921dff71af%40enterprisedb.com --- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_attribute.h | 34 ++++++++++++++++++---------------- src/include/catalog/pg_constraint.h | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src/include') diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index 69270c313f..c187d47eb2 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -57,6 +57,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202303231 +#define CATALOG_VERSION_NO 202303281 #endif diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h index b561e17781..f8b4861b94 100644 --- a/src/include/catalog/pg_attribute.h +++ b/src/include/catalog/pg_attribute.h @@ -52,15 +52,6 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75, */ Oid atttypid BKI_LOOKUP_OPT(pg_type); - /* - * attstattarget is the target number of statistics datapoints to collect - * during VACUUM ANALYZE of this column. A zero here indicates that we do - * not wish to collect any stats about this column. A "-1" here indicates - * that no value has been explicitly set for this column, so ANALYZE - * should use the default setting. - */ - int32 attstattarget BKI_DEFAULT(-1); - /* * attlen is a copy of the typlen field from pg_type for this attribute. * See atttypid comments above. @@ -82,12 +73,6 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75, */ int16 attnum; - /* - * attndims is the declared number of dimensions, if an array type, - * otherwise zero. - */ - int32 attndims; - /* * fastgetattr() uses attcacheoff to cache byte offsets of attributes in * heap tuples. The value actually stored in pg_attribute (-1) indicates @@ -105,6 +90,12 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75, */ int32 atttypmod BKI_DEFAULT(-1); + /* + * attndims is the declared number of dimensions, if an array type, + * otherwise zero. + */ + int16 attndims; + /* * attbyval is a copy of the typbyval field from pg_type for this * attribute. See atttypid comments above. @@ -165,7 +156,18 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75, bool attislocal BKI_DEFAULT(t); /* Number of times inherited from direct parent relation(s) */ - int32 attinhcount BKI_DEFAULT(0); + int16 attinhcount BKI_DEFAULT(0); + + /* + * attstattarget is the target number of statistics datapoints to collect + * during VACUUM ANALYZE of this column. A zero here indicates that we do + * not wish to collect any stats about this column. A "-1" here indicates + * that no value has been explicitly set for this column, so ANALYZE + * should use the default setting. + * + * int16 is sufficient because the max value is currently 10000. + */ + int16 attstattarget BKI_DEFAULT(-1); /* attribute's collation, if any */ Oid attcollation BKI_LOOKUP_OPT(pg_collation); diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h index 96889fddfa..16bf5f5576 100644 --- a/src/include/catalog/pg_constraint.h +++ b/src/include/catalog/pg_constraint.h @@ -102,7 +102,7 @@ CATALOG(pg_constraint,2606,ConstraintRelationId) bool conislocal; /* Number of times inherited from direct parent relation(s) */ - int32 coninhcount; + int16 coninhcount; /* Has a local definition and cannot be inherited */ bool connoinherit; -- cgit v1.2.3