mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
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
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user