Re: Re: [SQL] querying with index on jsonb slower than standard column. Why?

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Tim Dudgeon <tdudgeon(dot)ml(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-performance(at)postgresql(dot)org
Subject: Re: Re: [SQL] querying with index on jsonb slower than standard column. Why?
Date: 2014-12-12 21:24:04
Message-ID: 548B5CF4.4030009@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance pgsql-sql

On 12/08/2014 01:39 PM, Tim Dudgeon wrote:
> On 08/12/2014 18:14, Adrian Klaver wrote:
>> Recheck Cond: ((((data ->> 'assay1_ic50'::text))::double precision > 90::double precision) AND (((data ->> 'assay2_ic50'::text))::double precision < 10::double precision))
>> >
>> > which means we have to pull the JSONB value out of the tuple, search
>> > it to find the 'assay1_ic50' key, convert the associated value to text
>> > (which is not exactly cheap because *the value is stored as a numeric*),
>> > then reparse that text string into a float8, after which we can use
>> > float8gt. And then probably do an equivalent amount of work on the way
>> > to making the other comparison.
>> >
>> > So this says nothing much about the lossy-bitmap code, and a lot about
>> > how the JSONB code isn't very well optimized yet. In particular, the
>> > decision not to provide an operator that could extract a numeric field
>> > without conversion to text is looking pretty bad here.
> Yes, that bit seemed strange to me. As I understand the value is stored
> internally as numeric, but the only way to access it is as text and then
> cast back to numeric.
> I *think* this is the only way to do it presently?

Yeah, I believe the core problem is that Postgres currently doesn't have
any way to have variadic return times from a function which don't match
variadic input types. Returning a value as an actual numeric from JSONB
would require returning a numeric from a function whose input type is
text or json. So a known issue but one which would require a lot of
replumbing to fix.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2014-12-12 21:44:10 Re: Re: [SQL] querying with index on jsonb slower than standard column. Why?
Previous Message Merlin Moncure 2014-12-12 21:06:42 Re: 8xIntel S3500 SSD in RAID10 on Dell H710p

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2014-12-12 21:44:10 Re: Re: [SQL] querying with index on jsonb slower than standard column. Why?
Previous Message Tom Lane 2014-12-09 22:16:38 Re: Check/unique constraint question