Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdef4c28

Browse files
committed
Change JSONB's on-disk format for improved performance.
The original design used an array of offsets into the variable-lengthportion of a JSONB container. However, such an array is basicallyuncompressible by simple compression techniques such as TOAST's LZcompressor. That's bad enough, but because the offset array is at thefront, it tended to trigger the give-up-after-1KB heuristic in the TOASTcode, so that the entire JSONB object was stored uncompressed; which wasthe root cause of bug #11109 from Larry White.To fix without losing the ability to extract a random array element in O(1)time, change this scheme so that most of the JEntry array elements holdlengths rather than offsets. With data that's compressible at all, theretend to be fewer distinct element lengths, so that there is scope forcompression of the JEntry array. Every N'th entry is still an offset.To determine the length or offset of any specific element, we might haveto examine up to N preceding JEntrys, but that's still O(1) so far as thetotal container size is concerned. Testing shows that this cost isnegligible compared to other costs of accessing a JSONB field, and thatthe method does largely fix the incompressible-data problem.While at it, rearrange the order of elements in a JSONB object so thatit's "all the keys, then all the values" not alternating keys and values.This doesn't really make much difference right at the moment, but it willallow providing a fast path for extracting individual object fields fromlarge JSONB values stored EXTERNAL (ie, uncompressed), analogously to theexisting optimization for substring extraction from large EXTERNAL textvalues.Bump catversion to denote the incompatibility in on-disk format.We will need to fix pg_upgrade to disallow upgrading jsonb data storedwith 9.4 betas 1 and 2.Heikki Linnakangas and Tom Lane
1 parentff27fcf commitdef4c28

File tree

4 files changed

+357
-157
lines changed

4 files changed

+357
-157
lines changed

‎src/backend/utils/adt/jsonb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ jsonb_from_cstring(char *json, int len)
196196
staticsize_t
197197
checkStringLen(size_tlen)
198198
{
199-
if (len>JENTRY_POSMASK)
199+
if (len>JENTRY_OFFLENMASK)
200200
ereport(ERROR,
201201
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
202202
errmsg("string too long to represent as jsonb string"),
203203
errdetail("Due to an implementation restriction, jsonb strings cannot exceed %d bytes.",
204-
JENTRY_POSMASK)));
204+
JENTRY_OFFLENMASK)));
205205

206206
returnlen;
207207
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp