Skip to content

Commit e39c094

Browse files
author
Nikita Glukhov
committed
Add GUC jsonb_sort_field_values
1 parent 7b8069b commit e39c094

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-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)
@@ -2022,7 +2021,7 @@ convertJsonbObject(StringInfo buffer, JEntry *pheader, const JsonbValue *val, in
20222021
uint32 header;
20232022
int nPairs = val->val.object.nPairs;
20242023
int reserved_size;
2025-
bool sorted_values = JSONB_SORTED_VALUES && nPairs > 1;
2024+
bool sorted_values = jsonb_sort_field_values && nPairs > 1;
20262025
struct
20272026
{
20282027
int size;

src/backend/utils/misc/guc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#include "utils/bytea.h"
9292
#include "utils/float.h"
9393
#include "utils/guc_tables.h"
94+
#include "utils/jsonb.h"
9495
#include "utils/memutils.h"
9596
#include "utils/pg_locale.h"
9697
#include "utils/pg_lsn.h"
@@ -2084,6 +2085,15 @@ static struct config_bool ConfigureNamesBool[] =
20842085
NULL, NULL, NULL
20852086
},
20862087

2088+
{
2089+
{"jsonb_sort_field_values", PGC_USERSET, DEVELOPER_OPTIONS,
2090+
gettext_noop("Use special binary jsonb format for objects when their field values sorted by length."),
2091+
},
2092+
&jsonb_sort_field_values,
2093+
true,
2094+
NULL, NULL, NULL
2095+
},
2096+
20872097
/* End-of-list marker */
20882098
{
20892099
{NULL, 0, 0, NULL, NULL}, NULL, false, NULL, NULL, NULL

src/include/utils/jsonb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +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 */
417+
416418
#endif /* __JSONB_H__ */

0 commit comments

Comments
 (0)