Re: [HACKERS] Schizophrenic coding in gin_extract_jsonb(_hash)

2014-05-07 Thread Tom Lane
Heikki Linnakangas writes: > 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. Got it. So if the top level is empty, we can exit early, but otherwise we use its length * 2 as a guess at how big

Re: [HACKERS] Schizophrenic coding in gin_extract_jsonb(_hash)

2014-05-07 Thread Heikki Linnakangas
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 a

Re: [HACKERS] Schizophrenic coding in gin_extract_jsonb(_hash)

2014-05-07 Thread Tom Lane
Peter Geoghegan writes: > On Tue, May 6, 2014 at 8:08 PM, Tom Lane wrote: >> The early-exit code path supposes that JB_ROOT_COUNT is absolutely >> reliable as an indicator that there's nothing in the jsonb value. >> On the other hand, the realloc logic inside the iteration loop implies >> that JB

Re: [HACKERS] Schizophrenic coding in gin_extract_jsonb(_hash)

2014-05-06 Thread Peter Geoghegan
On Tue, May 6, 2014 at 8:08 PM, Tom Lane wrote: > The early-exit code path supposes that JB_ROOT_COUNT is absolutely > reliable as an indicator that there's nothing in the jsonb value. > On the other hand, the realloc logic inside the iteration loop implies > that JB_ROOT_COUNT is just an untrustw

[HACKERS] Schizophrenic coding in gin_extract_jsonb(_hash)

2014-05-06 Thread Tom Lane
Would someone care to defend this code? inttotal = 2 * JB_ROOT_COUNT(jb); ... if (total == 0) { *nentries = 0; PG_RETURN_POINTER(NULL); } ... while ((r = JsonbIteratorNext(&it, &v, false)) != WJB_DONE) { if (i >= total)