diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2024-01-13 18:14:53 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2024-01-13 18:14:53 +0100 |
commit | 4f622503d6de975ac87448aea5cea7de4bc140d5 (patch) | |
tree | c09756e667e5150678e8ebf9aee6c1cd5e376a96 /src/include | |
parent | 45da69371ebfc4d6982695e58791989660c1cc33 (diff) |
Make attstattarget nullable
This changes the pg_attribute field attstattarget into a nullable
field in the variable-length part of the row. If no value is set by
the user for attstattarget, it is now null instead of previously -1.
This saves space in pg_attribute and tuple descriptors for most
practical scenarios. (ATTRIBUTE_FIXED_PART_SIZE is reduced from 108
to 104.) Also, null is the semantically more correct value.
The ANALYZE code internally continues to represent the default
statistics target by -1, so that that code can avoid having to deal
with null values. But that is now contained to the ANALYZE code.
Only the DDL code deals with attstattarget possibly null.
For system columns, the field is now always null. The ANALYZE code
skips system columns anyway.
To set a column's statistics target to the default value, the new
command form ALTER TABLE ... SET STATISTICS DEFAULT can be used. (SET
STATISTICS -1 still works.)
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
Discussion: https://www.postgresql.org/message-id/flat/4da8d211-d54d-44b9-9847-f2a9f1184c76@eisentraut.org
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/catversion.h | 2 | ||||
-rw-r--r-- | src/include/catalog/pg_attribute.h | 20 | ||||
-rw-r--r-- | src/include/commands/vacuum.h | 2 | ||||
-rw-r--r-- | src/include/utils/lsyscache.h | 1 |
4 files changed, 12 insertions, 13 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index a94dcdc2713..460d80ac97e 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -57,6 +57,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 202401111 +#define CATALOG_VERSION_NO 202401131 #endif diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h index 7f4d308e8dd..e2aadb94141 100644 --- a/src/include/catalog/pg_attribute.h +++ b/src/include/catalog/pg_attribute.h @@ -158,22 +158,22 @@ CATALOG(pg_attribute,1249,AttributeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(75, /* Number of times inherited from direct parent relation(s) */ int16 attinhcount BKI_DEFAULT(0); + /* attribute's collation, if any */ + Oid attcollation BKI_LOOKUP_OPT(pg_collation); + +#ifdef CATALOG_VARLEN /* variable-length/nullable fields start here */ + /* NOTE: The following fields are not present in tuple descriptors. */ + /* * 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. + * not wish to collect any stats about this column. A null value here + * indicates that no value has been explicitly set for this column, so + * ANALYZE should use the default setting. * * int16 is sufficient for the current max value (MAX_STATISTICS_TARGET). */ - int16 attstattarget BKI_DEFAULT(-1); - - /* attribute's collation, if any */ - Oid attcollation BKI_LOOKUP_OPT(pg_collation); - -#ifdef CATALOG_VARLEN /* variable-length fields start here */ - /* NOTE: The following fields are not present in tuple descriptors. */ + int16 attstattarget BKI_DEFAULT(_null_) BKI_FORCE_NULL; /* Column-level access permissions */ aclitem attacl[1] BKI_DEFAULT(_null_); diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h index 5cacefc7670..7f623b37fdc 100644 --- a/src/include/commands/vacuum.h +++ b/src/include/commands/vacuum.h @@ -121,7 +121,7 @@ typedef struct VacAttrStats * than the underlying column/expression. Therefore, use these fields for * information about the datatype being fed to the typanalyze function. */ - int attstattarget; + int attstattarget; /* -1 to use default */ Oid attrtypid; /* type of data being analyzed */ int32 attrtypmod; /* typmod of data being analyzed */ Form_pg_type attrtype; /* copy of pg_type row for attrtypid */ diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index be9ed70e841..e4a200b00ec 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -90,7 +90,6 @@ extern Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum); extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok); extern AttrNumber get_attnum(Oid relid, const char *attname); -extern int get_attstattarget(Oid relid, AttrNumber attnum); extern char get_attgenerated(Oid relid, AttrNumber attnum); extern Oid get_atttype(Oid relid, AttrNumber attnum); extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum, |