Re: Abnormal JSON query performance - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Abnormal JSON query performance
Date
Msg-id 26540.1526275122@sss.pgh.pa.us
Whole thread Raw
In response to Abnormal JSON query performance  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: Abnormal JSON query performance  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Sunday, May 13, 2018, <007reader@gmail.com> wrote:
>> My interest is in fast access to data. On a relational table, the query
>> time is about the same whether I have one or ten fields in a select
>> statement. I’d love to see the same behavior when getting multiple keys
>> from a JSON document.

> I would hazard to say this is a solid desire and one shared by many.  It is
> also seemingly something that today has little or no precedent in
> PostgreSQL.  The lack is not a bug.

Yeah.  This has been discussed from time to time before.  The problem
is how to reconcile it with PG's extensible architecture, in which these
various -> and ->> operators are independent functions that are black
boxes so far as the core code is concerned.  It's very unclear how to
set up an arrangement that would let them share processing.

For the moment, you can work around it to some extent by writing out
the shared processing manually, along the lines of

select (x).this, (x).that, (x).the_other from
  (select jsonb_populate_record(null::myrowtype, jsonb_column) as x
   from ...) ss

where myrowtype defines the fields you want to extract.

            regards, tom lane


pgsql-bugs by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Abnormal JSON query performance
Next
From: Ralf Jung
Date:
Subject: "REVOKE ... ON DATABASE template1 ..." has no effect