Skip to content

Commit 6de0f21

Browse files
author
Nikita Glukhov
committed
Fix double detoasting of compressed jsonbs
1 parent b402076 commit 6de0f21

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,15 +2913,13 @@ jsonbzIteratorInit(JsonContainer *jc)
29132913
}
29142914

29152915
static void
2916-
jsonbzInit(JsonContainerData *jc, Datum value)
2916+
jsonbzInitFromCompresedDatum(JsonContainerData *jc, CompressedDatum *cd)
29172917
{
29182918
CompressedJsonb *cjb = palloc(sizeof(*cjb));
2919-
CompressedDatum *cd = palloc(sizeof(*cd));
29202919

29212920
cjb->datum = cd;
29222921
cjb->offset = offsetof(Jsonb, root);
29232922

2924-
CompressedDatumInit(cd, value);
29252923
if (!jsonb_partial_decompression)
29262924
CompressedDatumDecompressAll(cd);
29272925
else
@@ -2930,6 +2928,16 @@ jsonbzInit(JsonContainerData *jc, Datum value)
29302928
jsonbzInitContainer(jc, cjb, VARSIZE_ANY_EXHDR(cd->data)); // cd->total_len - VARHDRSZ
29312929
}
29322930

2931+
static void
2932+
jsonbzInit(JsonContainerData *jc, Datum value)
2933+
{
2934+
CompressedDatum *cd = palloc(sizeof(*cd));
2935+
2936+
CompressedDatumInit(cd, value);
2937+
2938+
jsonbzInitFromCompresedDatum(jc, cd);
2939+
}
2940+
29332941
JsonContainerOps
29342942
jsonbzContainerOps =
29352943
{
@@ -2973,7 +2981,8 @@ DatumGetJsonbPC(Datum datum, Json *tmp, bool copy)
29732981

29742982
js = JsonExpand(tmp, (Datum) 0, false, &jsonbzContainerOps);
29752983

2976-
jsonbzInit(&js->root, datum);
2984+
jsonbzInitFromCompresedDatum(&js->root,
2985+
memcpy(palloc(sizeof(cd)), &cd, sizeof(cd)));
29772986

29782987
return js;
29792988
}

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