postgresql/src/include/utils
Tom Lane def4c28cf9 Change JSONB's on-disk format for improved performance.
The original design used an array of offsets into the variable-length
portion of a JSONB container.  However, such an array is basically
uncompressible by simple compression techniques such as TOAST's LZ
compressor.  That's bad enough, but because the offset array is at the
front, it tended to trigger the give-up-after-1KB heuristic in the TOAST
code, so that the entire JSONB object was stored uncompressed; which was
the 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 hold
lengths rather than offsets.  With data that's compressible at all, there
tend to be fewer distinct element lengths, so that there is scope for
compression of the JEntry array.  Every N'th entry is still an offset.
To determine the length or offset of any specific element, we might have
to examine up to N preceding JEntrys, but that's still O(1) so far as the
total container size is concerned.  Testing shows that this cost is
negligible compared to other costs of accessing a JSONB field, and that
the method does largely fix the incompressible-data problem.

While at it, rearrange the order of elements in a JSONB object so that
it'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 will
allow providing a fast path for extracting individual object fields from
large JSONB values stored EXTERNAL (ie, uncompressed), analogously to the
existing optimization for substring extraction from large EXTERNAL text
values.

Bump catversion to denote the incompatibility in on-disk format.
We will need to fix pg_upgrade to disallow upgrading jsonb data stored
with 9.4 betas 1 and 2.

Heikki Linnakangas and Tom Lane
2014-09-29 12:29:21 -04:00
..
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
acl.h Row-Level Security Policies (RLS) 2014-09-19 11:18:35 -04:00
array.h Add width_bucket(anyelement, anyarray). 2014-09-09 15:34:14 -04:00
ascii.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
attoptcache.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
builtins.h Implement mxid_age() to compute multi-xid age 2014-09-10 17:13:04 -04:00
bytea.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
cash.h Add casts from int4 and int8 to numeric. 2011-04-05 09:35:43 -04:00
catcache.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
combocid.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
date.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
datetime.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
datum.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
dynahash.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
dynamic_loader.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
elog.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
evtcache.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
fmgrtab.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
formatting.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
geo_decls.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
guc_tables.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
guc.h Invent PGC_SU_BACKEND and mark log_connections/log_disconnections that way. 2014-09-13 21:01:57 -04:00
help_config.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
hsearch.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
inet.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
int8.h Provide moving-aggregate support for a bunch of numerical aggregates. 2014-04-12 20:33:09 -04:00
inval.h Introduce logical decoding. 2014-03-03 16:32:18 -05:00
json.h Add 'ignore_nulls' option to row_to_json 2014-09-11 21:23:51 -04:00
jsonapi.h Avoid some pnstrdup()s when constructing jsonb 2014-05-09 12:46:21 +03:00
jsonb.h Change JSONB's on-disk format for improved performance. 2014-09-29 12:29:21 -04:00
logtape.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
lsyscache.h Don't require sort support functions to provide a comparator. 2014-08-06 16:06:06 -04:00
memdebug.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
memutils.h Fix and enhance the assertion of no palloc's in a critical section. 2014-06-30 10:26:00 +03:00
nabstime.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
numeric.h Introduce jsonb, a structured format for storing json. 2014-03-23 16:40:19 -04:00
palloc.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_crc_tables.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_crc.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
pg_locale.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
pg_lsn.h Add btree and hash opclasses for pg_lsn. 2014-06-04 20:45:56 -04:00
pg_lzcompress.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
pg_rusage.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
plancache.h Row-Level Security Policies (RLS) 2014-09-19 11:18:35 -04:00
portal.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
ps_status.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
rangetypes.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
rbtree.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
rel.h Row-Level Security Policies (RLS) 2014-09-19 11:18:35 -04:00
relcache.h Code review for recent changes in relcache.c. 2014-05-14 14:56:08 -04:00
relfilenodemap.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
relmapper.h Add rmgr callback to name xlog record types for display purposes. 2014-09-19 16:20:29 +02:00
reltrigger.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
resowner_private.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
resowner.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
selfuncs.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
snapmgr.h Introduce logical decoding. 2014-03-03 16:32:18 -05:00
snapshot.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
sortsupport.h Update comment to reflect commit 1d41739e5a. 2014-09-04 12:17:10 -04:00
spccache.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
syscache.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
timeout.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
timestamp.h Provide moving-aggregate support for a bunch of numerical aggregates. 2014-04-12 20:33:09 -04:00
tqual.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
tuplesort.h Avoid copying index tuples when building an index. 2014-07-01 10:34:42 -04:00
tuplestore.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
typcache.h pgindent run for 9.4 2014-05-06 12:12:18 -04:00
tzparser.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
uuid.h Update copyright for 2014 2014-01-07 16:05:30 -05:00
varbit.h Predict integer overflow to avoid buffer overruns. 2014-02-17 09:33:31 -05:00
xml.h Update copyright for 2014 2014-01-07 16:05:30 -05:00