Skip to content

Commit d54b299

Browse files
author
Nikita Glukhov
committed
Add GUC jsonb_sort_field_values
1 parent cd87628 commit d54b299

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/backend/utils/adt/jsonb_util.c

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

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

141+
bool jsonb_sort_field_values = true; /* GUC */
143142

144143
JsonValue *
145144
JsonValueUnpackBinary(const JsonValue *jbv)
@@ -1959,7 +1958,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, in
19591958
uint32 header;
19601959
int nPairs = val->val.object.nPairs;
19611960
int reserved_size;
1962-
bool sorted_values = JSONB_SORTED_VALUES && nPairs > 1;
1961+
bool sorted_values = jsonb_sort_field_values && nPairs > 1;
19631962
struct
19641963
{
19651964
int size;

src/backend/utils/misc/guc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
#include "utils/bytea.h"
9191
#include "utils/float.h"
9292
#include "utils/guc_tables.h"
93+
#include "utils/jsonb.h"
9394
#include "utils/memutils.h"
9495
#include "utils/pg_locale.h"
9596
#include "utils/pg_lsn.h"
@@ -2036,6 +2037,15 @@ static struct config_bool ConfigureNamesBool[] =
20362037
NULL, NULL, NULL
20372038
},
20382039

2040+
{
2041+
{"jsonb_sort_field_values", PGC_USERSET, DEVELOPER_OPTIONS,
2042+
gettext_noop("Use special binary jsonb format for objects when their field values sorted by length."),
2043+
},
2044+
&jsonb_sort_field_values,
2045+
true,
2046+
NULL, NULL, NULL
2047+
},
2048+
20392049
/* End-of-list marker */
20402050
{
20412051
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL

src/include/utils/jsonb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,5 +413,6 @@ extern void JsonbHashScalarValueExtended(const JsonbValue *scalarVal,
413413
extern int reserveFromBuffer(StringInfo buffer, int len);
414414
extern void appendToBuffer(StringInfo buffer, const void *data, int len);
415415

416+
extern bool jsonb_sort_field_values; /* GUC */
416417

417418
#endif /* __JSONB_H__ */

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