Re: Schizophrenic coding in gin_extract_jsonb(_hash)

From: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Geoghegan <pg(at)heroku(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Schizophrenic coding in gin_extract_jsonb(_hash)
Date: 2014-05-07 16:38:42
Message-ID: 536A6192.9050109@vmware.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-05-07 16:42:03 Re: PGDLLEXPORTing all GUCs?
Previous Message Stephen Frost 2014-05-07 16:33:17 Re: [v9.5] Custom Plan API