- Notifications
You must be signed in to change notification settings - Fork5
Commitdef4c28
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 Lane1 parentff27fcf commitdef4c28
File tree
4 files changed
+357
-157
lines changed- src
- backend/utils/adt
- include
- catalog
- utils
4 files changed
+357
-157
lines changedLines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
196 | 196 |
| |
197 | 197 |
| |
198 | 198 |
| |
199 |
| - | |
| 199 | + | |
200 | 200 |
| |
201 | 201 |
| |
202 | 202 |
| |
203 | 203 |
| |
204 |
| - | |
| 204 | + | |
205 | 205 |
| |
206 | 206 |
| |
207 | 207 |
| |
|
0 commit comments
Comments
(0)