From c7b99583bfc4155ec4c80710deb14f7b463a6537 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Thu, 14 Aug 2025 12:54:58 +0900 Subject: [PATCH v1 08/11] Add relation option toast_value_type This relation option gives the possibility to define the attribute type that can be used for chunk_id in a TOAST table when it is created initially. This parameter has no effect if a TOAST table exists, even after it is modified later on, even on rewrites. This can be set only to "oid" currently, and will be expanded with a second mode later. Note: perhaps it would make sense to introduce that only when support for 8-byte OID values are added to TOAST, the split is here to ease review. --- src/include/utils/rel.h | 17 +++++++++++++++++ src/backend/access/common/reloptions.c | 21 +++++++++++++++++++++ src/backend/catalog/toasting.c | 6 ++++++ src/bin/psql/tab-complete.in.c | 1 + doc/src/sgml/ref/create_table.sgml | 18 ++++++++++++++++++ 5 files changed, 63 insertions(+) diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index cd1e92f23025..f3be0acd4255 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -340,11 +340,20 @@ typedef enum StdRdOptIndexCleanup STDRD_OPTION_VACUUM_INDEX_CLEANUP_ON, } StdRdOptIndexCleanup; +/* StdRdOptions->toast_value_type values */ +typedef enum StdRdOptToastValueType +{ + STDRD_OPTION_TOAST_VALUE_TYPE_INVALID = 0, + STDRD_OPTION_TOAST_VALUE_TYPE_OID, +} StdRdOptToastValueType; + typedef struct StdRdOptions { int32 vl_len_; /* varlena header (do not touch directly!) */ int fillfactor; /* page fill factor in percent (0..100) */ int toast_tuple_target; /* target for tuple toasting */ + StdRdOptToastValueType toast_value_type; /* type assigned to chunk_id + * at toast table creation */ AutoVacOpts autovacuum; /* autovacuum-related options */ bool user_catalog_table; /* use as an additional catalog relation */ int parallel_workers; /* max number of parallel workers */ @@ -369,6 +378,14 @@ typedef struct StdRdOptions ((relation)->rd_options ? \ ((StdRdOptions *) (relation)->rd_options)->toast_tuple_target : (defaulttarg)) +/* + * RelationGetToastValueType + * Returns the relation's toast_value_type. Note multiple eval of argument! + */ +#define RelationGetToastValueType(relation, defaulttarg) \ + ((relation)->rd_options ? \ + ((StdRdOptions *) (relation)->rd_options)->toast_value_type : defaulttarg) + /* * RelationGetFillFactor * Returns the relation's fillfactor. Note multiple eval of argument! diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c index 3e832c3797e8..66fd2a05538e 100644 --- a/src/backend/access/common/reloptions.c +++ b/src/backend/access/common/reloptions.c @@ -548,6 +548,14 @@ static relopt_enum_elt_def viewCheckOptValues[] = {(const char *) NULL} /* list terminator */ }; +/* values from StdRdOptToastValueType */ +static relopt_enum_elt_def StdRdOptToastValueTypes[] = +{ + /* no value for INVALID */ + {"oid", STDRD_OPTION_TOAST_VALUE_TYPE_OID}, + {(const char *) NULL} /* list terminator */ +}; + static relopt_enum enumRelOpts[] = { { @@ -561,6 +569,17 @@ static relopt_enum enumRelOpts[] = STDRD_OPTION_VACUUM_INDEX_CLEANUP_AUTO, gettext_noop("Valid values are \"on\", \"off\", and \"auto\".") }, + { + { + "toast_value_type", + "Controls the attribute type of chunk_id at toast table creation", + RELOPT_KIND_HEAP, + ShareUpdateExclusiveLock + }, + StdRdOptToastValueTypes, + STDRD_OPTION_TOAST_VALUE_TYPE_OID, + gettext_noop("Valid values are \"oid\".") + }, { { "buffering", @@ -2008,6 +2027,8 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind) offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, log_analyze_min_duration)}, {"toast_tuple_target", RELOPT_TYPE_INT, offsetof(StdRdOptions, toast_tuple_target)}, + {"toast_value_type", RELOPT_TYPE_ENUM, + offsetof(StdRdOptions, toast_value_type)}, {"autovacuum_vacuum_cost_delay", RELOPT_TYPE_REAL, offsetof(StdRdOptions, autovacuum) + offsetof(AutoVacOpts, vacuum_cost_delay)}, {"autovacuum_vacuum_scale_factor", RELOPT_TYPE_REAL, diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c index bc0a72268335..28ddbd10d357 100644 --- a/src/backend/catalog/toasting.c +++ b/src/backend/catalog/toasting.c @@ -159,9 +159,15 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, */ if (!IsBinaryUpgrade) { + StdRdOptToastValueType value_type; + /* Normal mode, normal check */ if (!needs_toast_table(rel)) return false; + + value_type = RelationGetToastValueType(rel, STDRD_OPTION_TOAST_VALUE_TYPE_OID); + if (value_type == STDRD_OPTION_TOAST_VALUE_TYPE_OID) + toast_chunkid_typid = OIDOID; } else { diff --git a/src/bin/psql/tab-complete.in.c b/src/bin/psql/tab-complete.in.c index db65d130fcbb..8f6d448e8df8 100644 --- a/src/bin/psql/tab-complete.in.c +++ b/src/bin/psql/tab-complete.in.c @@ -1463,6 +1463,7 @@ static const char *const table_storage_parameters[] = { "toast.vacuum_max_eager_freeze_failure_rate", "toast.vacuum_truncate", "toast_tuple_target", + "toast_value_type", "user_catalog_table", "vacuum_index_cleanup", "vacuum_max_eager_freeze_failure_rate", diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index e342585c7f08..3da754045c04 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -1653,6 +1653,24 @@ WITH ( MODULUS numeric_literal, REM + + toast_value_type (enum) + + toast_value_type storage parameter + + + + + The toast_value_type specifies the attribute type of + chunk_id used when initially creating a toast + relation for this table. + By default this parameter is oid, to assign + oid as attribute type to chunk_id. + This parameter cannot be set for TOAST tables. + + + + parallel_workers (integer) -- 2.54.0