Skip to content

Commit 07ca6c2

Browse files
author
Commitfest Bot
committed
[CF 5702] v19 - ZStandard (with dictionaries) compression support for TOAST compression
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5702 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAFAfj_H1cQQh1nDYa6+TuJozk-8Q013_6n8XboX9-xRqbmAZfw@mail.gmail.com Author(s): Nikhil Kumar Veldanda
2 parents 368c3fb + 465f41a commit 07ca6c2

21 files changed

+458
-66
lines changed

contrib/amcheck/verify_heapam.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1786,12 +1786,14 @@ check_tuple_attribute(HeapCheckContext *ctx)
17861786
bool valid = false;
17871787

17881788
/* Compressed attributes should have a valid compression method */
1789-
cmid = TOAST_COMPRESS_METHOD(&toast_pointer);
1789+
cmid = toast_get_compression_id(attr);
1790+
17901791
switch (cmid)
17911792
{
17921793
/* List of all valid compression method IDs */
17931794
case TOAST_PGLZ_COMPRESSION_ID:
17941795
case TOAST_LZ4_COMPRESSION_ID:
1796+
case TOAST_ZSTD_NODICT_COMPRESSION_ID:
17951797
valid = true;
17961798
break;
17971799

src/backend/access/brin/brin_tuple.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
223223
{
224224
Datum cvalue;
225225
char compression;
226+
CompressionInfo cmp;
226227
Form_pg_attribute att = TupleDescAttr(brdesc->bd_tupdesc,
227228
keyno);
228229

@@ -237,7 +238,8 @@ brin_form_tuple(BrinDesc *brdesc, BlockNumber blkno, BrinMemTuple *tuple,
237238
else
238239
compression = InvalidCompressionMethod;
239240

240-
cvalue = toast_compress_datum(value, compression);
241+
cmp = setup_compression_info(compression, att);
242+
cvalue = toast_compress_datum(value, cmp);
241243

242244
if (DatumGetPointer(cvalue) != NULL)
243245
{

src/backend/access/common/detoast.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ detoast_attr_slice(struct varlena *attr,
246246
* Determine maximum amount of compressed data needed for a prefix
247247
* of a given length (after decompression).
248248
*
249-
* At least for now, if it's LZ4 data, we'll have to fetch the
250-
* whole thing, because there doesn't seem to be an API call to
251-
* determine how much compressed data we need to be sure of being
252-
* able to decompress the required slice.
249+
* At least for now, if it's LZ4 or Zstandard data, we'll have to
250+
* fetch the whole thing, because there doesn't seem to be an API
251+
* call to determine how much compressed data we need to be sure
252+
* of being able to decompress the required slice.
253253
*/
254254
if (VARATT_EXTERNAL_GET_COMPRESS_METHOD(toast_pointer) ==
255255
TOAST_PGLZ_COMPRESSION_ID)
@@ -478,13 +478,15 @@ toast_decompress_datum(struct varlena *attr)
478478
* Fetch the compression method id stored in the compression header and
479479
* decompress the data using the appropriate decompression routine.
480480
*/
481-
cmid = TOAST_COMPRESS_METHOD(attr);
481+
cmid = VARDATA_COMPRESSED_GET_COMPRESS_METHOD(attr);
482482
switch (cmid)
483483
{
484484
case TOAST_PGLZ_COMPRESSION_ID:
485485
return pglz_decompress_datum(attr);
486486
case TOAST_LZ4_COMPRESSION_ID:
487487
return lz4_decompress_datum(attr);
488+
case TOAST_ZSTD_NODICT_COMPRESSION_ID:
489+
return zstd_decompress_datum(attr);
488490
default:
489491
elog(ERROR, "invalid compression method id %d", cmid);
490492
return NULL; /* keep compiler quiet */
@@ -514,20 +516,22 @@ toast_decompress_datum_slice(struct varlena *attr, int32 slicelength)
514516
* have been seen to give wrong results if passed an output size that is
515517
* more than the data's true decompressed size.
516518
*/
517-
if ((uint32) slicelength >= TOAST_COMPRESS_EXTSIZE(attr))
519+
if ((uint32) slicelength >= VARDATA_COMPRESSED_GET_EXTSIZE(attr))
518520
return toast_decompress_datum(attr);
519521

520522
/*
521523
* Fetch the compression method id stored in the compression header and
522524
* decompress the data slice using the appropriate decompression routine.
523525
*/
524-
cmid = TOAST_COMPRESS_METHOD(attr);
526+
cmid = VARDATA_COMPRESSED_GET_COMPRESS_METHOD(attr);
525527
switch (cmid)
526528
{
527529
case TOAST_PGLZ_COMPRESSION_ID:
528530
return pglz_decompress_datum_slice(attr, slicelength);
529531
case TOAST_LZ4_COMPRESSION_ID:
530532
return lz4_decompress_datum_slice(attr, slicelength);
533+
case TOAST_ZSTD_NODICT_COMPRESSION_ID:
534+
return zstd_decompress_datum_slice(attr, slicelength);
531535
default:
532536
elog(ERROR, "invalid compression method id %d", cmid);
533537
return NULL; /* keep compiler quiet */

src/backend/access/common/indextuple.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,10 @@ index_form_tuple_context(TupleDesc tupleDescriptor,
123123
att->attstorage == TYPSTORAGE_MAIN))
124124
{
125125
Datum cvalue;
126+
CompressionInfo cmp;
126127

127-
cvalue = toast_compress_datum(untoasted_values[i],
128-
att->attcompression);
128+
cmp = setup_compression_info(att->attcompression, att);
129+
cvalue = toast_compress_datum(untoasted_values[i], cmp);
129130

130131
if (DatumGetPointer(cvalue) != NULL)
131132
{

src/backend/access/common/reloptions.c

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "access/nbtree.h"
2525
#include "access/reloptions.h"
2626
#include "access/spgist_private.h"
27+
#include "access/toast_compression.h"
2728
#include "catalog/pg_type.h"
2829
#include "commands/defrem.h"
2930
#include "commands/tablespace.h"
@@ -381,7 +382,15 @@ static relopt_int intRelOpts[] =
381382
},
382383
-1, 0, 1024
383384
},
384-
385+
{
386+
{
387+
"zstd_level",
388+
"Set column's ZSTD compression level",
389+
RELOPT_KIND_ATTRIBUTE,
390+
ShareUpdateExclusiveLock
391+
},
392+
DEFAULT_ZSTD_LEVEL, MIN_ZSTD_LEVEL, MAX_ZSTD_LEVEL
393+
},
385394
/* list terminator */
386395
{{NULL}}
387396
};
@@ -2097,7 +2106,8 @@ attribute_reloptions(Datum reloptions, bool validate)
20972106
{
20982107
static const relopt_parse_elt tab[] = {
20992108
{"n_distinct", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct)},
2100-
{"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)}
2109+
{"n_distinct_inherited", RELOPT_TYPE_REAL, offsetof(AttributeOpts, n_distinct_inherited)},
2110+
{"zstd_level", RELOPT_TYPE_INT, offsetof(AttributeOpts, zstd_level)},
21012111
};
21022112

21032113
return (bytea *) build_reloptions(reloptions, validate,

0 commit comments

Comments
 (0)