mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +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:
@@ -232,11 +232,10 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
|
||||
* same compression method. Otherwise we have to use the
|
||||
* default method.
|
||||
*/
|
||||
if (att->atttypid == atttype->type_id &&
|
||||
CompressionMethodIsValid(att->attcompression))
|
||||
if (att->atttypid == atttype->type_id)
|
||||
compression = att->attcompression;
|
||||
else
|
||||
compression = GetDefaultToastCompression();
|
||||
compression = InvalidCompressionMethod;
|
||||
|
||||
cvalue = toast_compress_datum(value, compression);
|
||||
|
||||
|
||||
@@ -104,18 +104,9 @@ index_form_tuple(TupleDesc tupleDescriptor,
|
||||
att->attstorage == TYPSTORAGE_MAIN))
|
||||
{
|
||||
Datum cvalue;
|
||||
char compression = att->attcompression;
|
||||
|
||||
/*
|
||||
* If the compression method is not valid, use the default. We
|
||||
* don't expect this to happen for regular index columns, which
|
||||
* inherit the setting from the corresponding table column, but we
|
||||
* do expect it to happen whenever an expression is indexed.
|
||||
*/
|
||||
if (!CompressionMethodIsValid(compression))
|
||||
compression = GetDefaultToastCompression();
|
||||
|
||||
cvalue = toast_compress_datum(untoasted_values[i], compression);
|
||||
cvalue = toast_compress_datum(untoasted_values[i],
|
||||
att->attcompression);
|
||||
|
||||
if (DatumGetPointer(cvalue) != NULL)
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -642,10 +642,7 @@ TupleDescInitEntry(TupleDesc desc,
|
||||
att->attbyval = typeForm->typbyval;
|
||||
att->attalign = typeForm->typalign;
|
||||
att->attstorage = typeForm->typstorage;
|
||||
if (IsStorageCompressible(typeForm->typstorage))
|
||||
att->attcompression = GetDefaultToastCompression();
|
||||
else
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcollation = typeForm->typcollation;
|
||||
|
||||
ReleaseSysCache(tuple);
|
||||
@@ -711,7 +708,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
|
||||
att->attbyval = false;
|
||||
att->attalign = TYPALIGN_INT;
|
||||
att->attstorage = TYPSTORAGE_EXTENDED;
|
||||
att->attcompression = GetDefaultToastCompression();
|
||||
att->attcompression = InvalidCompressionMethod;
|
||||
att->attcollation = DEFAULT_COLLATION_OID;
|
||||
break;
|
||||
|
||||
|
||||
@@ -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