Re: [BUGS] BUG #10728: json_to_recordset with nested json objects NULLs columns - Mailing list pgsql-hackers

From Merlin Moncure
Subject Re: [BUGS] BUG #10728: json_to_recordset with nested json objects NULLs columns
Date
Msg-id CAHyXU0wiJ78MD8Sap9RL4-yigC_d5dKdPDvQ+nKUsVPqCUTfZg@mail.gmail.com
Whole thread Raw
In response to Re: [BUGS] BUG #10728: json_to_recordset with nested json objects NULLs columns  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Mon, Jun 23, 2014 at 10:43 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Michael Paquier <michael.paquier@gmail.com> writes:
>> Digging more into that, I have found the issue and a fix for it. It happens
>> that populate_recordset_object_start, which is used to initialize the
>> process for the population of the record, is taken *each* time a json
>> object is found, re-creating every time the hash table for the parsing
>> process, hence removing from PopulateRecordsetState all the entries already
>> parsed and creating the problem reported by Matti. The fix I am proposing
>> to fix this issue is rather simple: simply bypass the creation of the hash
>> table if lex_level > 1 as we are in presence of a nested object and rely on
>> the existing hash table.
>
> Yes, this code is clearly not handling the nested-objects case correctly.
> I had written a fix more or less equivalent to yours last night.
>
> However, it seems to me that these functions (json[b]_to_record[set]) are
> handling the nested-json-objects case in a fairly brain-dead fashion to
> start with.  I would like to propose that we should think about getting
> rid of the use_json_as_text flag arguments altogether.  What purpose do
> they serve?  If we're going to the trouble of parsing the nested JSON
> objects anyway, why don't we just reconstruct from that data?

I think they should be removed.  (I called this out in the feature
level review:
http://www.postgresql.org/message-id/CAHyXU0wqadCJk7MMkeARuuY05VrD=AXDn6wDceMtuWo5p4CUiA@mail.gmail.com).
AIUI, the flag was introduced as a workaround to try and deal with
mapping nested structures.  Text variant 'json' flags have had them.

merlin



pgsql-hackers by date:

Previous
From: "MauMau"
Date:
Subject: Re: Use a signal to trigger a memory context dump?
Next
From: Vik Fearing
Date:
Subject: Re: please review source(SQLServer compatible)‏