pgsql: Clean up jsonb code.

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Clean up jsonb code.
Date: 2014-05-07 20:18:30
Message-ID: E1Wi8IQ-0001UT-RJ@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Clean up jsonb code.

The main target of this cleanup is the convertJsonb() function, but I also
touched a lot of other things that I spotted into in the process.

The new convertToJsonb() function uses an output buffer that's resized on
demand, so the code to estimate of the size of JsonbValue is removed.

The on-disk format was not changed, even though I refactored the structs
used to handle it. The term "superheader" is replaced with "container".

The jsonb_exists_any and jsonb_exists_all functions no longer sort the input
array. That was a premature optimization, the idea being that if there are
duplicates in the input array, you only need to check them once. Also,
sorting the array saves some effort in the binary search used to find a key
within an object. But there were drawbacks too: the sorting and
deduplicating obviously isn't free, and in the typical case there are no
duplicates to remove, and the gain in the binary search was minimal. Remove
all that, which makes the code simpler too.

This includes a bug-fix; the total length of the elements in a jsonb array
or object mustn't exceed 2^28. That is now checked.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/364ddc3e5cbd01c93a39896b5260509129a9883e

Modified Files
--------------
src/backend/utils/adt/jsonb.c | 16 +-
src/backend/utils/adt/jsonb_gin.c | 4 +-
src/backend/utils/adt/jsonb_op.c | 106 ++--
src/backend/utils/adt/jsonb_util.c | 929 +++++++++++++-----------------------
src/backend/utils/adt/jsonfuncs.c | 64 +--
src/include/utils/jsonb.h | 213 +++++----
6 files changed, 556 insertions(+), 776 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2014-05-07 20:19:56 pgsql: Restart bgworkers immediately after a crash-and-restart cycle.
Previous Message Robert Haas 2014-05-07 18:57:03 pgsql: Detach shared memory from bgworkers without shmem access.

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2014-05-07 20:32:24 Re: bgworker crashed or not?
Previous Message Tom Lane 2014-05-07 20:13:33 Re: Wanted: jsonb on-disk representation documentation