diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-05-27 13:24:24 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-05-27 13:24:27 -0400 |
commit | e6241d8e030fbd2746b3ea3f44e728224298f35b (patch) | |
tree | e4bfc50561023459635cb9faf0873fee1e891013 /src/backend/access/heap/heapam_handler.c | |
parent | a717e5c771610cf8607f2423ab3ab6b5d30f44ea (diff) | |
download | postgresql-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/heap/heapam_handler.c')
-rw-r--r-- | src/backend/access/heap/heapam_handler.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index 8e6e8d51698..e2cd79ec546 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -2483,10 +2483,10 @@ reform_and_rewrite_tuple(HeapTuple tuple, * perform the compression here; we just need to decompress. That * will trigger recompression later on. */ - struct varlena *new_value; ToastCompressionId cmid; char cmethod; + char targetmethod; new_value = (struct varlena *) DatumGetPointer(values[i]); cmid = toast_get_compression_id(new_value); @@ -2495,7 +2495,7 @@ reform_and_rewrite_tuple(HeapTuple tuple, if (cmid == TOAST_INVALID_COMPRESSION_ID) continue; - /* convert compression id to compression method */ + /* convert existing compression id to compression method */ switch (cmid) { case TOAST_PGLZ_COMPRESSION_ID: @@ -2506,10 +2506,16 @@ reform_and_rewrite_tuple(HeapTuple tuple, break; default: elog(ERROR, "invalid compression method id %d", cmid); + cmethod = '\0'; /* keep compiler quiet */ } + /* figure out what the target method is */ + targetmethod = TupleDescAttr(newTupDesc, i)->attcompression; + if (!CompressionMethodIsValid(targetmethod)) + targetmethod = default_toast_compression; + /* if compression method doesn't match then detoast the value */ - if (TupleDescAttr(newTupDesc, i)->attcompression != cmethod) + if (targetmethod != cmethod) { values[i] = PointerGetDatum(detoast_attr(new_value)); values_free[i] = true; |