Re: Schizophrenic coding in gin_extract_jsonb(_hash) - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Schizophrenic coding in gin_extract_jsonb(_hash)
Date
Msg-id 536A6192.9050109@vmware.com
Whole thread Raw
In response to Re: Schizophrenic coding in gin_extract_jsonb(_hash)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Schizophrenic coding in gin_extract_jsonb(_hash)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 05/07/2014 06:27 PM, Tom Lane wrote:
> I think you're just proving the point that this code is woefully
> underdocumented.  If there were, somewhere, some comment explaining
> what the heck JB_ROOT_COUNT actually counts, maybe I wouldn't be asking
> this question.  jsonb.h is certainly not divulging any such information.

After having reverse-engineered the convertJsonb code, I think I can 
explain what JB_ROOT_COUNT is.

If the root of the Jsonb datum is an array, it's the number of elements 
in that top-level array. If it's an object, it's the number of key/value 
pairs in that top-level object. Some of the elements of that array (or 
values of the object) can be arrays or objects themselves.

gin_extract_jsonb recursively extracts all the elements, keys and values 
of any sub-object too, but JB_ROOT_COUNT only counts the top-level elements.

(I hope this is made a bit more clear in the comments I added in the 
patch I posted this morning)

- Heikki



pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: [v9.5] Custom Plan API
Next
From: Andres Freund
Date:
Subject: Re: PGDLLEXPORTing all GUCs?