8000 Added another single byte oriented decompressor, useful for · postgrespro/postgres_cluster@4069d48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4069d48

Browse files
Jan WieckJan Wieck
authored andcommitted
Added another single byte oriented decompressor, useful for
comparision functions. Added all lztext comparision functions, operators and a default operator class for nbtree on lztext. Jan
1 parent 4ae43c8 commit 4069d48

File tree

9 files changed

+435
-9
lines changed

9 files changed

+435
-9
lines changed

src/backend/utils/adt/lztext.c

Lines changed: 144 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ----------
22
* lztext.c -
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.3 1999/11/24 03:45:12 ishii Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/lztext.c,v 1.4 1999/11/25 01:28:04 wieck Exp $
55
*
66
* Text type with internal LZ compressed representation. Uses the
77
* standard PostgreSQL compression method.
@@ -290,3 +290,146 @@ lztext_text(lztext *lz)
290290
}
291291

292292

293+
/* ----------
294+
* lztext_cmp -
295+
*
296+
* Comparision function for two lztext datum's.
297+
*
298+
* Returns -1, 0 or 1.
299+
* ----------
300+
*/
301+
int32
302+
lztext_cmp(lztext *lz1, lztext *lz2)
303+
{
304+
#ifdef USE_LOCALE
305+
306+
char *cp1;
307+
char *cp2;
308+
int result;
309+
310+
if (lz1 == NULL || lz2 == NULL)
311+
return (int32)0;
312+
313+
cp1 = lztextout(lz1);
314+
cp2 = lztextout(lz2);
315+
316+
result = strcoll(cp1, cp2);
317+
318+
pfree(cp1);
319+
pfree(cp2);
320+
321+
return result;
322+
323+
#else /* !USE_LOCALE */
324+
325+
PGLZ_DecompState ds1;
326+
PGLZ_DecompState ds2;
327+
int c1;
328+
int c2;
329+
int32 result = (int32)0;
330+
331+
if (lz1 == NULL || lz2 == NULL)
332+
return (int32)0;
333+
334+
pglz_decomp_init(&ds1, lz1);
335+
pglz_decomp_init(&ds2, lz2);
336+
337+
for(;;)
338+
{
339+
c1 = pglz_decomp_getchar(&ds1);
340+
c2 = pglz_decomp_getchar(&ds2);
341+
342+
if (c1 == EOF)
343+
{
344+
if (c2 != EOF)
345+
result = (int32)-1;
346+
break;
347+
} else {
348+
if (c2 == EOF)
349+
{
350+
result = (int32)1;
351+
}
352+
}
353+
if (c1 != c2)
354+
{
355+
result = (int32)(c1 - c2);
356+
break;
357+
}
358+
}
359+
360+
pglz_decomp_end(&ds1);
361+
pglz_decomp_end(&ds2);
362+
363+
return result;
364+
365+
#endif /* USE_LOCALE */
366+
}
367+
368+
369+
/* ----------
370+
* lztext_eq ... -
371+
*
372+
* =, !=, >, >=, < and <= operator functions for two
373+
* lztext datums.
374+
* ----------
375+
*/
376+
bool
377+
lztext_eq(lztext *lz1, lztext *lz2)
378+
{
379+
if (lz1 == NULL || lz2 == NULL)
380+
return false;
381+
382+
return (bool)(lztext_cmp(lz1, lz2) == 0);
383+
}
384+
385+
386+
bool
387+
lztext_ne(lztext *lz1, lztext *lz2)
388+
{
389+
if (lz1 == NULL || lz2 == NULL)
390+
return false;
391+
392+
return (bool)(lztext_cmp(lz1, lz2) != 0);
393+
}
394+
395+
396+
bool
397+
lztext_gt(lztext *lz1, lztext *lz2)
398+
{
399+
if (lz1 == NULL || lz2 == NULL)
400+
return false;
401+
402+
return (bool)(lztext_cmp(lz1, lz2) > 0);
403+
}
404+
405+
406+
bool
407+
lztext_ge(lztext *lz1, lztext *lz2)
408+
{
409+
if (lz1 == NULL || lz2 == NULL)
410+
return false;
411+
412+
return (bool)(lztext_cmp(lz1, lz2) >= 0);
413+
}
414+
415+
416+
bool
417+
lztext_lt(lztext *lz1, lztext *lz2)
418+
{
419+
if (lz1 == NULL || lz2 == NULL)
420+
return false;
421+
422+
return (bool)(lztext_cmp(lz1, lz2) < 0);
423+
}
424+
425+
426+
bool
427+
lztext_le(lztext *lz1, lztext *lz2)
428+
{
429+
if (lz1 == NULL || lz2 == NULL)
430+
return false;
431+
432+
return (bool)(lztext_cmp(lz1, lz2) <= 0);
433+
}
434+
435+

src/backend/utils/adt/pg_lzcompress.c

Lines changed: 165 additions & 1 deletion
F987
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.2 1999/11/17 22:18:45 wieck Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.3 1999/11/25 01:28:04 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
@@ -671,3 +671,167 @@ pglz_decompress (PGLZ_Header *source, char *dest)
671671
}
672672

673673

674+
/* ----------
675+
* pglz_get_next_decomp_char_from_lzdata -
676+
*
677+
* Reads the next character from a decompression state if the
678+
* input data to pglz_decomp_init() was in compressed format.
679+
* ----------
680+
*/
681+
int
682+
pglz_get_next_decomp_char_from_lzdata(PGLZ_DecompState *dstate)
683+
{
684+
unsigned char retval;
685+
686+
if (dstate->tocopy > 0)
687+
{
688+
/* ----------
689+
* Copy one byte from output to output until we did it
690+
* for the length specified by the last tag. Return that
691+
* byte.
692+
* ----------
693+
*/
694+
dstate->tocopy--;
695+
return (*(dstate->cp_out++) = *(dstate->cp_copy++));
696+
}
697+
698+
if (dstate->ctrl_count == 0)
699+
{
700+
/* ----------
701+
* Get the next control byte if we need to, but check
702+
* for EOF before.
703+
* ----------
704+
*/
705+
if (dstate->cp_in == dstate->cp_end)
706+
{
707+
return EOF;
708+
}
709+
710+
/* ----------
711+
* This decompression method saves time only, if we stop near
712+
* the beginning of the data (maybe because we're called by a
713+
* comparision function and a difference occurs early). Otherwise,
714+
* all the checks, needed here, cause too much overhead.
715+
*
716+
* Thus we decompress the entire rest at once into the temporary
717+
* buffer and change the decomp state to return the prepared
718+
* data from the buffer by the more simple calls to
719+
* pglz_get_next_decomp_char_from_plain().
720+
* ----------
721+
*/
722+
if (dstate->cp_out - dstate->temp_buf >= 256)
723+
{
724+
unsigned char *cp_in = dstate->cp_in;
725+
unsigned char *cp_out = dstate->cp_out;
726+
unsigned char *cp_end = dstate->cp_end;
727+
unsigned char *cp_copy;
728+
unsigned char ctrl;
729+
int off;
730+
int len;
731+
int i;
732+
733+
while (cp_in < cp_end)
734+
{
735+
ctrl = *cp_in++;
736+
737+
for (i = 0; i < 8; i++)
738+
{
739+
if (cp_in == cp_end)
740+
break;
741+
742+
if (ctrl & 0x01)
743+
{
744+
len = (cp_in[0] & 0x0f) + 3;
745+
off = ((cp_in[0] & 0xf0) << 4) | cp_in[1];
746+
cp_in += 2;
747+
if (len == 18)
748+
len += *cp_in++;
749+
750+
cp_copy = cp_out - off;
751+
while(len--)
752+
*cp_out++ = *cp_copy++;
753+
} else {
754+
*cp_out++ = *cp_in++;
755+
}
756+
ctrl >>= 1;
757+
}
758+
}
759+
760+
dstate->cp_in = dstate->cp_out;
761+
dstate->cp_end = cp_out;
762+
dstate->next_char = pglz_get_next_decomp_char_from_plain;
763+
764+
return (int)(*(dstate->cp_in++));
765+
}
766+
767+
/* ----------
768+
* Not yet, get next control byte into decomp state.
769+
* ----------
770+
*/
771+
dstate->ctrl = (unsigned char)(*(dstate->cp_in++));
772+
dstate->ctrl_count = 8;
773+
}
774+
775+
/* ----------
776+
* Check for EOF in tag/literal byte data.
777+
* ----------
778+
*/
779+
if (dstate->cp_in == dstate->cp_end)
780+
{
781+
return EOF;
782+
}
783+
784+
/* ----------
785+
* Handle next control bit.
786+
* ----------
787+
*/
788+
dstate->ctrl_count--;
789+
if (dstate->ctrl & 0x01)
790+
{
791+
/* ----------
792+
* Bit is set, so tag is following. Setup copy information
793+
* and do the copy for the first byte as above.
794+
* ----------
795+
*/
796+
int off;
797+
798+
dstate->tocopy = (dstate->cp_in[0] & 0x0f) + 3;
799+
off = ((dstate->cp_in[0] & 0xf0) << 4) | dstate->cp_in[1];
800+
dstate->cp_in += 2;
801+
if (dstate->tocopy == 18)
802+
dstate->tocopy += *(dstate->cp_in++);
803+
dstate->cp_copy = dstate->cp_out - off;
804+
805+
dstate->tocopy--;
806+
retval = (*(dstate->cp_out++) = *(dstate->cp_copy++));
807+
} else {
808+
/* ----------
809+
* Bit is unset, so literal byte follows.
810+
* ----------
811+
*/
812+
retval = (int)(*(dstate->cp_out++) = *(dstate->cp_in++));
813+
}
814+
dstate->ctrl >>= 1;
815+
816+
return (int)retval;
817+
}
818+
819+
820+
/* ----------
821+
* pglz_get_next_decomp_char_from_plain -
822+
*
823+
* The input data to pglz_decomp_init() was stored in uncompressed
824+
* format. So we don't have a temporary output buffer and simply
825+
* return bytes from the input until EOF.
826+
* ----------
827+
*/
828+
int
829+
pglz_get_next_decomp_char_from_plain(PGLZ_DecompState *dstate)
830+
{
831+
if (dstate->cp_in >= dstate->cp_end)
832+
return EOF;
833+
834+
return (int)(*(dstate->cp_in++));
835+
}
836+
837+

src/include/catalog/pg_amop.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_amop.h,v 1.24 1999/09/29 21:13:30 wieck Exp $
10+
* $Id: pg_amop.h,v 1.25 1999/11/25 01:28:05 wieck Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -348,6 +348,16 @@ DATA(insert OID = 0 ( 403 1768 1752 3 btreesel btreenpage ));
348348
DATA(insert OID = 0 ( 403 1768 1757 4 btreesel btreenpage ));
349349
DATA(insert OID = 0 ( 403 1768 1756 5 btreesel btreenpage ));
350350

351+
/*
352+
* nbtree lztext
353+
*/
354+
355+
DATA(insert OID = 0 ( 403 1663 1659 1 btreesel btreenpage ));
356+
DATA(insert OID = 0 ( 403 1663 1660 2 btreesel btreenpage ));
357+
DATA(insert OID = 0 ( 403 1663 1657 3 btreesel btreenpage ));
358+
DATA(insert OID = 0 ( 403 1663 1662 4 btreesel btreenpage ));
359+
DATA(insert OID = 0 ( 403 1663 1661 5 btreesel btreenpage ));
360+
351361
/*
352362
* hash table _ops
353363
*/

src/include/catalog/pg_amproc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Copyright (c) 1994, Regents of the University of California
1111
*
12-
* $Id: pg_amproc.h,v 1.15 1999/09/29 21:13:30 wieck Exp $
12+
* $Id: pg_amproc.h,v 1.16 1999/11/25 01:28:05 wieck Exp $
1313
*
1414
* NOTES
1515
* the genbki.sh script reads this file and generates .bki
@@ -97,6 +97,7 @@ DATA(insert OID = 0 (403 1313 1315 1));
9797
DATA(insert OID = 0 (403 810 836 1));
9898
DATA(insert OID = 0 (403 935 926 1));
9999
DATA(insert OID = 0 (403 1768 1769 1));
100+
DATA(insert OID = 0 (403 1663 1636 1));
100101

101102

102103
/* hash */

src/include/catalog/pg_opclass.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_opclass.h,v 1.22 1999/11/23 04:47:39 momjian Exp $
10+
* $Id: pg_opclass.h,v 1.23 1999/11/25 01:28:05 wieck Exp $
1111
*
1212
* NOTES
1313
* the genbki.sh script reads this file and generates .bki
@@ -117,5 +117,7 @@ DATA(insert OID = 652 ( cidr_ops 650 ));
117117
DESCR("");
118118
DATA(insert OID = 1768 ( numeric_ops 1700 ));
119119
DESCR("");
120+
DATA(insert OID = 1663 ( lztext_ops 1625 ));
121+
DESCR("");
120122

121123
#endif /* PG_OPCLASS_H */

0 commit comments

Comments
 (0)
0