Skip to content

Commit e9a81fb

Browse files
author
Nikita Glukhov
committed
Add GUC jsonb_sort_field_values
1 parent 5df33e2 commit e9a81fb

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/backend/utils/adt/jsonb_util.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "utils/memutils.h"
3131
#include "utils/varlena.h"
3232

33-
#define JSONB_SORTED_VALUES 1
34-
3533
/*
3634
* Maximum number of elements in an array (or key/value pairs in an object).
3735
* This is limited by two things: the size of the JEntry array must fit
@@ -137,6 +135,7 @@ static JsonbValue *fillCompressedJsonbValue(CompressedJsonb *cjb,
137135
uint32 offset, JsonValue *result);
138136
static JsonbContainer *jsonbzDecompress(JsonContainer *jc);
139137

138+
bool jsonb_sort_field_values = true; /* GUC */
140139
bool jsonb_partial_decompression = true; /*GUC */
141140

142141
JsonValue *
@@ -2032,7 +2031,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, in
20322031
uint32 header;
20332032
int nPairs = val->val.object.nPairs;
20342033
int reserved_size;
2035-
bool sorted_values = JSONB_SORTED_VALUES && nPairs > 1;
2034+
bool sorted_values = jsonb_sort_field_values && nPairs > 1;
20362035
struct
20372036
{
20382037
int size;

src/backend/utils/misc/guc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,15 @@ static struct config_bool ConfigureNamesBool[] =
21832183
NULL, NULL, NULL
21842184
},
21852185

2186+
{
2187+
{"jsonb_sort_field_values", PGC_USERSET, DEVELOPER_OPTIONS,
2188+
gettext_noop("Use special binary jsonb format for objects when their field values sorted by length."),
2189+
},
2190+
&jsonb_sort_field_values,
2191+
true,
2192+
NULL, NULL, NULL
2193+
},
2194+
21862195
{
21872196
{"jsonb_partial_decompression", PGC_USERSET, DEVELOPER_OPTIONS,
21882197
gettext_noop("Use partial pglz decompression for jsonb."),

src/include/utils/jsonb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ extern Datum jsonb_build_object_worker(int nargs, Datum *args, bool *nulls,
250250
extern Datum jsonb_build_array_worker(int nargs, Datum *args, bool *nulls,
251251
Oid *types, bool absent_on_null);
252252

253+
extern bool jsonb_sort_field_values; /* GUC */
253254
extern bool jsonb_partial_decompression; /* GUC */
254255

255256
#endif /* __JSONB_H__ */

0 commit comments

Comments
 (0)