Skip to content

Commit 332a0f6

Browse files
author
Nikita Glukhov
committed
WIP
1 parent 102f464 commit 332a0f6

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

src/backend/access/common/detoast.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ create_detoast_iterator(struct varlena *attr)
343343
/* initialize state for pglz_decompress_iterate() */
344344
iter->ctrl = 0;
345345
iter->ctrlc = INVALID_CTRLC;
346+
iter->len = 0;
347+
iter->off = 0;
346348
}
347349
else
348350
{
@@ -368,7 +370,7 @@ create_detoast_iterator(struct varlena *attr)
368370
return create_detoast_iterator(attr);
369371

370372
}
371-
else if (VARATT_IS_COMPRESSED(attr))
373+
else if (1 && VARATT_IS_COMPRESSED(attr))
372374
{
373375
ToastBuffer *buf;
374376

src/backend/access/common/toast_internals.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,33 @@ pglz_decompress_iterate(ToastBuffer *source, ToastBuffer *dest,
906906
(source->limit == source->capacity ? source->limit : (source->limit - 4));
907907
sp = (const unsigned char *) source->position;
908908
dp = (unsigned char *) dest->limit;
909-
if (destend < (unsigned char *) dest->capacity)
909+
if (destend > (unsigned char *) dest->capacity)
910910
destend = (unsigned char *) dest->capacity;
911911

912+
if (iter->len)
913+
{
914+
int32 len = iter->len;
915+
int32 off = iter->off;
916+
int32 copylen = Min(len, destend - dp);
917+
int32 remlen = len - copylen;
918+
919+
while (copylen--)
920+
{
921+
*dp = dp[-off];
922+
dp++;
923+
}
924+
925+
iter->len = remlen;
926+
927+
if (dp >= destend)
928+
{
929+
dest->limit = (char *) dp;
930+
return;
931+
}
932+
933+
Assert(remlen == 0);
934+
}
935+
912936
while (sp < srcend && dp < destend)
913937
{
914938
/*
@@ -929,7 +953,6 @@ pglz_decompress_iterate(ToastBuffer *source, ToastBuffer *dest,
929953
ctrlc = 0;
930954
}
931955

932-
933956
for (; ctrlc < INVALID_CTRLC && sp < srcend && dp < destend; ctrlc++)
934957
{
935958

@@ -946,6 +969,7 @@ pglz_decompress_iterate(ToastBuffer *source, ToastBuffer *dest,
946969
*/
947970
int32 len;
948971
int32 off;
972+
int32 copylen;
949973

950974
len = (sp[0] & 0x0f) + 3;
951975
off = ((sp[0] & 0xf0) << 4) | sp[1];
@@ -959,17 +983,21 @@ pglz_decompress_iterate(ToastBuffer *source, ToastBuffer *dest,
959983
* areas could overlap; to prevent possible uncertainty, we
960984
* copy only non-overlapping regions.
961985
*/
962-
len = Min(len, destend - dp);
963-
while (off < len)
986+
copylen = Min(len, destend - dp);
987+
iter->len = len - copylen;
988+
989+
while (off < copylen)
964990
{
965991
/* see comments in common/pg_lzcompress.c */
966992
memcpy(dp, dp - off, off);
967-
len -= off;
993+
copylen -= off;
968994
dp += off;
969995
off += off;
970996
}
971-
memcpy(dp, dp - off, len);
972-
dp += len;
997+
memcpy(dp, dp - off, copylen);
998+
dp += copylen;
999+
1000+
iter->off = off;
9731001
}
9741002
else
9751003
{

src/include/access/detoast.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ typedef struct DetoastIteratorData
133133
unsigned char ctrl;
134134
int ctrlc;
135135
int nrefs;
136+
int32 len;
137+
int32 off;
136138
bool compressed; /* toast value is compressed? */
137139
bool done;
138140
} DetoastIteratorData;
@@ -184,16 +186,16 @@ detoast_iterate(DetoastIterator detoast_iter, const char *destend)
184186
if (!detoast_iter->compressed)
185187
destend = NULL;
186188

187-
if (destend)
189+
if (1 && destend)
188190
{
189191
const char *srcend = (const char *)
190192
(fetch_iter->buf->limit == fetch_iter->buf->capacity ?
191193
fetch_iter->buf->limit : fetch_iter->buf->limit - 4);
192194

193-
if (fetch_iter->buf->position >= srcend)
195+
if (fetch_iter->buf->position >= srcend && !fetch_iter->done)
194196
fetch_datum_iterate(fetch_iter);
195197
}
196-
else
198+
else if (!fetch_iter->done)
197199
fetch_datum_iterate(fetch_iter);
198200

199201
if (detoast_iter->compressed)

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