Skip to content

Commit d03a62e

Browse files
author
Nikita Glukhov
committed
Optimize jsonb returning, Json allocation
1 parent 7beaa1e commit d03a62e

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
@@ -2911,6 +2911,9 @@ DatumGetJsonbPC(Datum datum, Json *tmp, bool copy)
29112911
datum = PointerGetDatum(pg_detoast_datum_copy(src));
29122912
}
29132913

2914+
if (!jsonb_partial_decompression)
2915+
return DatumGetJson(datum, &jsonbContainerOps, tmp);
2916+
29142917
CompressedDatumInit(&cd, datum);
29152918

29162919
if (!cd.compressed)

src/backend/utils/adt/jsonfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ jsonb_object_field(PG_FUNCTION_ARGS)
644644
PG_GETARG_TEXT_PP(1));
645645

646646
if (res)
647-
PG_RETURN_JSONB_P(JsonbValueToJsonb(res));
647+
PG_RETURN_JSONB_VALUE(res);
648648
else
649649
PG_RETURN_NULL();
650650
}

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