Schizophrenic coding in gin_extract_jsonb(_hash)

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Schizophrenic coding in gin_extract_jsonb(_hash)
Дата
Msg-id 11791.1399432092@sss.pgh.pa.us
обсуждение исходный текст
Ответы Re: Schizophrenic coding in gin_extract_jsonb(_hash)  (Peter Geoghegan <pg@heroku.com>)
Список pgsql-hackers
Would someone care to defend this code?
   int            total = 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)       {           total *= 2;
        entries = (Datum *) repalloc(entries, sizeof(Datum) * total);       }
 

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 untrustworthy estimate.  Which theory is
correct?  And why is there not a comment to be seen anywhere?  If the code
is correct then this logic is certainly worthy of a comment or three.
        regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Fabrízio de Royes Mello
Дата:
Сообщение: Re: New pg_lsn type doesn't have hash/btree opclasses
Следующее
От: Tom Lane
Дата:
Сообщение: Re: need xmllint on borka