aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/common/toast_internals.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-05-27 13:24:24 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-05-27 13:24:27 -0400
commite6241d8e030fbd2746b3ea3f44e728224298f35b (patch)
treee4bfc50561023459635cb9faf0873fee1e891013 /src/backend/access/common/toast_internals.c
parenta717e5c771610cf8607f2423ab3ab6b5d30f44ea (diff)
downloadpostgresql-e6241d8e030fbd2746b3ea3f44e728224298f35b.tar.gz
postgresql-e6241d8e030fbd2746b3ea3f44e728224298f35b.zip
Rethink definition of pg_attribute.attcompression.
Redefine '\0' (InvalidCompressionMethod) as meaning "if we need to compress, use the current setting of default_toast_compression". This allows '\0' to be a suitable default choice regardless of datatype, greatly simplifying code paths that initialize tupledescs and the like. It seems like a more user-friendly approach as well, because now the default compression choice doesn't migrate into table definitions, meaning that changing default_toast_compression is usually sufficient to flip an installation's behavior; one needn't tediously issue per-column ALTER SET COMPRESSION commands. Along the way, fix a few minor bugs and documentation issues with the per-column-compression feature. Adopt more robust APIs for SetIndexStorageProperties and GetAttributeCompression. Bump catversion because typical contents of attcompression will now be different. We could get away without doing that, but it seems better to ensure v14 installations all agree on this. (We already forced initdb for beta2, anyway.) Discussion: https://postgr.es/m/626613.1621787110@sss.pgh.pa.us
Diffstat (limited to 'src/backend/access/common/toast_internals.c')
-rw-r--r--src/backend/access/common/toast_internals.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/access/common/toast_internals.c b/src/backend/access/common/toast_internals.c
index 8d2a9964c3f..c7b9ade5742 100644
--- a/src/backend/access/common/toast_internals.c
+++ b/src/backend/access/common/toast_internals.c
@@ -53,10 +53,12 @@ toast_compress_datum(Datum value, char cmethod)
Assert(!VARATT_IS_EXTERNAL(DatumGetPointer(value)));
Assert(!VARATT_IS_COMPRESSED(DatumGetPointer(value)));
- Assert(CompressionMethodIsValid(cmethod));
-
valsize = VARSIZE_ANY_EXHDR(DatumGetPointer(value));
+ /* If the compression method is not valid, use the current default */
+ if (!CompressionMethodIsValid(cmethod))
+ cmethod = default_toast_compression;
+
/*
* Call appropriate compression routine for the compression method.
*/