Skip to content

Commit 3648854

Browse files
committed
fixup! Add pglz compression method
1 parent f98aa91 commit 3648854

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

src/backend/access/compression/cm_pglz.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,43 @@ static struct varlena *
135135
pglz_cmdecompress(CompressionAmOptions *cmoptions, const struct varlena *value)
136136
{
137137
struct varlena *result;
138-
int32 resultlen;
138+
int32 rawsize;
139139

140140
Assert(VARATT_IS_CUSTOM_COMPRESSED(value));
141-
resultlen = VARRAWSIZE_4B_C(value) + VARHDRSZ;
142-
result = (struct varlena *) palloc(resultlen);
141+
result = (struct varlena *) palloc(VARRAWSIZE_4B_C(value) + VARHDRSZ);
143142

144143
SET_VARSIZE(result, resultlen);
145-
if (pglz_decompress((char *) value + VARHDRSZ_CUSTOM_COMPRESSED,
144+
rawsize = pglz_decompress((char *) value + VARHDRSZ_CUSTOM_COMPRESSED,
146145
VARSIZE(value) - VARHDRSZ_CUSTOM_COMPRESSED,
147146
VARDATA(result),
148-
VARRAWSIZE_4B_C(value)) < 0)
147+
VARRAWSIZE_4B_C(value), true);
148+
149+
if (rawsize < 0)
150+
elog(ERROR, "pglz: compressed data is corrupted");
151+
152+
SET_VARSIZE(result, rawsize);
153+
return result;
154+
}
155+
156+
static struct varlena *
157+
pglz_cmdecompress_slice(CompressionAmOptions *cmoptions, const struct varlena *value,
158+
int32 slicelength)
159+
{
160+
struct varlena *result;
161+
int32 rawsize;
162+
163+
Assert(VARATT_IS_CUSTOM_COMPRESSED(value));
164+
result = (struct varlena *) palloc(VARRAWSIZE_4B_C(value) + VARHDRSZ);
165+
166+
rawsize = pglz_decompress((char *) value + VARHDRSZ_CUSTOM_COMPRESSED,
167+
VARSIZE(value) - VARHDRSZ_CUSTOM_COMPRESSED,
168+
VARDATA(result),
169+
slicelength, false);
170+
171+
if (rawsize < 0)
149172
elog(ERROR, "pglz: compressed data is corrupted");
150173

174+
SET_VARSIZE(result, rawsize);
151175
return result;
152176
}
153177

@@ -161,6 +185,7 @@ pglzhandler(PG_FUNCTION_ARGS)
161185
routine->cminitstate = pglz_cminitstate;
162186
routine->cmcompress = pglz_cmcompress;
163187
routine->cmdecompress = pglz_cmdecompress;
188+
routine->cmdecompress_slice = pglz_cmdecompress_slice;
164189

165190
PG_RETURN_POINTER(routine);
166191
}

src/backend/access/compression/cm_zlib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ zlibhandler(PG_FUNCTION_ARGS)
246246
routine->cminitstate = zlib_cminitstate;
247247
routine->cmcompress = zlib_cmcompress;
248248
routine->cmdecompress = zlib_cmdecompress;
249+
routine->cmdecompress_slice = NULL;
249250

250251
PG_RETURN_POINTER(routine);
251252
#endif

src/backend/access/heap/tuptoaster.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,7 @@ toast_decompress_datum(struct varlena *attr)
24502450
rawsize = pglz_decompress(TOAST_COMPRESS_RAWDATA(attr),
24512451
VARSIZE(attr) - TOAST_COMPRESS_HDRSZ,
24522452
VARDATA(result),
2453-
TOAST_COMPRESS_RAWSIZE(attr));
2453+
TOAST_COMPRESS_RAWSIZE(attr), true);
24542454
if (rawsize < 0)
24552455
elog(ERROR, "compressed data is corrupted");
24562456

@@ -2482,7 +2482,10 @@ toast_decompress_datum_slice(struct varlena *attr, int32 slicelength)
24822482

24832483
hdr = (toast_compress_header_custom *) attr;
24842484
cmoptions = lookup_compression_am_options(hdr->cmid);
2485-
result = cmoptions->amroutine->cmdecompress_slice(cmoptions, attr, slicelength);
2485+
if (cmoptions->amroutine->cmdecompress_slice)
2486+
result = cmoptions->amroutine->cmdecompress_slice(cmoptions, attr, slicelength);
2487+
else
2488+
result = cmoptions->amroutine->cmdecompress(cmoptions, attr);
24862489
}
24872490
else
24882491
{

src/include/access/cmapi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ typedef struct CompressionAmOptions
4646
typedef void (*cmcheck_function) (Form_pg_attribute att, List *options);
4747
typedef struct varlena *(*cmcompress_function)
4848
(CompressionAmOptions *cmoptions, const struct varlena *value);
49+
typedef struct varlena *(*cmdecompress_slice_function)
50+
(CompressionAmOptions *cmoptions, const struct varlena *value,
51+
int32 slicelength);
4952
typedef void *(*cminitstate_function) (Oid acoid, List *options);
5053

5154
/*
@@ -70,6 +73,7 @@ struct CompressionAmRoutine
7073
cminitstate_function cminitstate; /* can be NULL */
7174
cmcompress_function cmcompress;
7275
cmcompress_function cmdecompress;
76+
cmdecompress_slice_function cmdecompress_slice;
7377
};
7478

7579
/* access/compression/cmapi.c */

0 commit comments

Comments
 (0)