Skip to content

Commit 9032dd5

Browse files
author
Nikita Glukhov
committed
Optimize jsonb returning, Json allocation
1 parent 6de0f21 commit 9032dd5

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,9 @@ DatumGetJsonbPC(Datum datum, Json *tmp, bool copy)
29742974
datum = PointerGetDatum(pg_detoast_datum_copy(src));
29752975
}
29762976

2977+
if (!jsonb_partial_decompression)
2978+
return DatumGetJson(datum, &jsonbContainerOps, tmp);
2979+
29772980
CompressedDatumInit(&cd, datum);
29782981

29792982
if (!cd.compressed)

src/backend/utils/adt/jsonfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ jsonb_object_field(PG_FUNCTION_ARGS)
638638
PG_GETARG_TEXT_PP(1));
639639

640640
if (res)
641-
PG_RETURN_JSONB_P(JsonbValueToJsonb(res));
641+
PG_RETURN_JSONB_VALUE(res);
642642
else
643643
PG_RETURN_NULL();
644644
}

src/include/utils/json_generic.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ typedef struct Json
9797
#define JsonbPGetDatum(json) JsonFlattenToJsonbDatum(JsonGetUniquified(json))
9898
#define JsontPGetDatum(json) CStringGetTextDatum(JsonToCString(JsonRoot(json), NULL))
9999

100+
#define JsonValueGetJsonbDatum(json) PointerGetDatum(JsonValueFlatten(json, JsonbEncode, &jsonbContainerOps))
101+
100102
#ifdef JsonxPGetDatum
101103
# define JsonGetDatum(json) JsonxPGetDatum(json)
102104
#else
@@ -117,6 +119,7 @@ typedef struct Json
117119
#undef PG_RETURN_JSONB_P
118120
#define PG_RETURN_JSONB_P(x) PG_RETURN_DATUM(JsonGetDatum(x))
119121
#define PG_RETURN_JSONT_P(x) PG_RETURN_DATUM(JsontPGetDatum(x))
122+
#define PG_RETURN_JSONB_VALUE(x) PG_RETURN_DATUM(JsonValueGetJsonbDatum(x))
120123

121124
#define PG_GETARG_JSONX_TMP(n, tmp) DatumGetJsonxTmp(PG_GETARG_DATUM(n), tmp)
122125

@@ -126,7 +129,7 @@ typedef struct Json
126129
#else
127130
#define PG_GETARG_JSONB_P(n) PG_GETARG_JSONX_TMP(n, alloca(sizeof(Json))) /* FIXME conditional alloca() */
128131
#endif
129-
#define PG_GETARG_JSONB_PC(n) DatumGetJsonbPC(PG_GETARG_DATUM(n), NULL /*alloca(sizeof(Json))*/, false) /* FIXME conditional alloca() */
132+
#define PG_GETARG_JSONB_PC(n) DatumGetJsonbPC(PG_GETARG_DATUM(n), alloca(JsonAllocSize(16)) /* FIXME sizeof CompressedJsonb */, false)
130133
#define PG_GETARG_JSONT_P(n) DatumGetJsontP(PG_GETARG_DATUM(n))
131134

132135
#undef PG_GETARG_JSONB_P_COPY

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