Skip to content

Commit 211ed36

Browse files
Jan WieckJan Wieck
authored andcommitted
Some minor corrections to the LZ compression. In fact I wanted to
HAVE the required OID's first. Jan
1 parent 79c3b71 commit 211ed36

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

src/backend/utils/adt/lztext.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/* ----------
22
* lztext.c -
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.1 1999/11/17 21:21:50 wieck Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.2 1999/11/17 22:18:45 wieck Exp $
55
*
66
* Text type with internal LZ compressed representation. Uses the
77
* standard PostgreSQL compression method.
8+
*
9+
* This code requires that the LZ compressor found in pg_lzcompress
10+
* codes a usable VARSIZE word at the beginning of the output buffer.
811
* ----------
912
*/
1013

@@ -42,7 +45,7 @@ lztextin(char *str)
4245
return NULL;
4346

4447
/* ----------
45-
* Determine input size and eventually tuple size
48+
* Determine input size and maximum output Datum size
4649
* ----------
4750
*/
4851
rawsize = strlen(str);
@@ -56,8 +59,9 @@ lztextin(char *str)
5659
pglz_compress(str, rawsize, tmp, NULL);
5760

5861
/* ----------
59-
* If we miss less than x% bytes at the end of the temp value,
60-
* so be it. Therefore we save a memcpy().
62+
* If we miss less than 25% bytes at the end of the temp value,
63+
* so be it. Therefore we save a palloc()/memcpy()/pfree()
64+
* sequence.
6165
* ----------
6266
*/
6367
if (tmp_size - tmp->varsize < 256 ||
@@ -141,7 +145,7 @@ lztextlen(lztext *lz)
141145
* without multibyte support, it's the remembered rawsize
142146
* ----------
143147
*/
144-
return lz->rawsize;
148+
return PGLZ_RAW_SIZE(lz);
145149
}
146150

147151

@@ -166,7 +170,7 @@ lztextoctetlen(lztext *lz)
166170
* Return the varsize minus the VARSIZE field itself.
167171
* ----------
168172
*/
169-
return lz->varsize - sizeof(int32);
173+
return VARSIZE(lz) - VARHDRSZ;
170174
}
171175

172176

@@ -208,8 +212,9 @@ text_lztext(text *txt)
208212
pglz_compress(str, rawsize, tmp, NULL);
209213

210214
/* ----------
211-
* If we miss less than x% bytes at the end of the temp value,
212-
* so be it. Therefore we save a memcpy().
215+
* If we miss less than 25% bytes at the end of the temp value,
216+
* so be it. Therefore we save a palloc()/memcpy()/pfree()
217+
* sequence.
213218
* ----------
214219
*/
215220
if (tmp_size - tmp->varsize < 256 ||
@@ -250,15 +255,15 @@ lztext_text(lztext *lz)
250255
* Allocate and initialize the text result
251256
* ----------
252257
*/
253-
result = (text *) palloc(lz->rawsize + VARHDRSZ + 1);
258+
result = (text *) palloc(PGLZ_RAW_SIZE(lz) + VARHDRSZ + 1);
254259
VARSIZE(result) = lz->rawsize + VARHDRSZ;
255260

256261
/* ----------
257262
* Decompress directly into the text data area.
258263
* ----------
259264
*/
260-
pglz_decompress(lz, VARDATA(result));
261265
VARDATA(result)[lz->rawsize] = 0;
266+
pglz_decompress(lz, VARDATA(result));
262267

263268
return result;
264269
}

src/backend/utils/adt/pg_lzcompress.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ----------
22
* pg_lzcompress.c -
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.1 1999/11/17 21:21:50 wieck Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.2 1999/11/17 22:18:45 wieck Exp $
55
*
66
* This is an implementation of LZ compression for PostgreSQL.
77
* It uses a simple history table and generates 2-3 byte tags
@@ -385,6 +385,8 @@ pglz_find_match (PGLZ_HistEntry **hstart, char *input, char *end,
385385

386386
/* ----------
387387
* pglz_compress -
388+
*
389+
* Compresses source into dest using strategy.
388390
* ----------
389391
*/
390392
int
@@ -580,6 +582,8 @@ pglz_compress (char *source, int slen, PGLZ_Header *dest, PGLZ_Strategy *strateg
580582

581583
/* ----------
582584
* pglz_decompress -
585+
*
586+
* Decompresses source into dest.
583587
* ----------
584588
*/
585589
int

src/include/utils/pg_lzcompress.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ----------
22
* pg_lzcompress.h -
33
*
4-
* $Header: /cvsroot/pgsql/src/include/utils/pg_lzcompress.h,v 1.1 1999/11/17 21:21:51 wieck Exp $
4+
* $Header: /cvsroot/pgsql/src/include/utils/pg_lzcompress.h,v 1.2 1999/11/17 22:18:46 wieck Exp $
55
*
66
* Definitions for the builtin LZ compressor
77
* ----------
@@ -37,9 +37,36 @@ typedef struct PGLZ_Header {
3737
*/
3838
#define PGLZ_MAX_OUTPUT(_dlen) ((_dlen) + (((_dlen) | 0x07) >> 3) \
3939
+ sizeof(PGLZ_Header))
40+
41+
/* ----------
42+
* PGLZ_RAW_SIZE -
43+
*
44+
* Macro to determine the uncompressed data size contained
45+
* in the entry.
46+
* ----------
47+
*/
4048
#define PGLZ_RAW_SIZE(_lzdata) (_lzdata->rawsize)
49+
50+
/* ----------
51+
* PGLZ_IS_COMPRESSED -
52+
*
53+
* Macro to determine if the data itself is stored as raw
54+
* uncompressed data.
55+
* ----------
56+
*/
4157
#define PGLZ_IS_COMPRESSED(_lzdata) (_lzdata->varsize != \
42-
_lzdata->rawsize + sizeof(PGLZ_Header))
58+
_lzdata->rawsize + \
59+
sizeof(PGLZ_Header))
60+
61+
/* ----------
62+
* PGLZ_RAW_DATA -
63+
*
64+
* Macro to get access to the plain compressed or uncompressed
65+
* data. Useful if PGLZ_IS_COMPRESSED returns false.
66+
* ----------
67+
*/
68+
#define PGLZ_RAW_DATA(_lzdata) (((char *)(_lzdata)) + \
69+
sizeof(PGLZ_Header))
4370

4471
/* ----------
4572
* PGLZ_Strategy -

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy