agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Tim Dudgeon <tdudgeon.ml@gmail.com>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-performance@postgresql.org
Subject: Re: querying with index on jsonb slower than standard column. Why?
Date: Mon, 08 Dec 2014 13:14:48 -0800
Message-ID: <548614C8.90203@aklaver.com> (raw)
In-Reply-To: <3936.1418071989@sss.pgh.pa.us>
References: <5484DBDA.6090405@gmail.com>
	<5484EEA7.1030403@aklaver.com>
	<5484F437.2080402@gmail.com>
	<16147.1418002090@sss.pgh.pa.us>
	<5485C449.4020204@aklaver.com>
	<26002.1418053572@sss.pgh.pa.us>
	<5485C8BA.7040704@aklaver.com>
	<5485D584.8080105@aklaver.com>
	<27877.1418057764@sss.pgh.pa.us>
	<3936.1418071989@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

On 12/08/2014 12:53 PM, Tom Lane wrote:
> I wrote:
>> Adrian Klaver <adrian.klaver@aklaver.com> writes:
>>> Seems work_mem is the key:
> 
>> Fascinating.  So there's some bad behavior in the lossy-bitmap stuff
>> that's exposed by one case but not the other.
> 
> Meh.  I was overthinking it.  A bit of investigation with oprofile exposed
> the true cause of the problem: whenever the bitmap goes lossy, we have to
> execute the "recheck" condition for each tuple in the page(s) that the
> bitmap has a lossy reference to.  So in the fast case we are talking about
> 
> Recheck Cond: ((assay1_ic50 > 90::double precision) AND (assay2_ic50 < 10::double precision))
> 
> which involves little except pulling the float8 values out of the tuple
> and executing float8gt and float8lt.  In the slow case we have got
> 
> 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.
> 

I think I understand the above.

I redid the test on my 32-bit machine, setting work_mem=16MB, and I got comparable results
to what I saw on the 64-bit machine. So, what I am still am puzzled by is why work_mem seems 
to make the two paths equivalent in time?:

Fast case, assay1_ic50 > 90 and assay2_ic50 < 10:
1183.997 ms

Slow case, (data->>'assay1_ic50')::float > 90 and (data->>'assay2_ic50')::float < 10;:
1190.187 ms

> 
> 			regards, tom lane
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (24+ messages)  latest in thread

Message-ID: <548614C8.90203@aklaver.com>
Permalink:  ../548614C8.90203@aklaver.com/
Also on:    postgresql.org/message-id/548614C8.90203@aklaver.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: adrian.klaver@aklaver.com, tgl@sss.pgh.pa.us, tdudgeon.ml@gmail.com, pgsql-performance@postgresql.org
  Subject: Re: querying with index on jsonb slower than standard column. Why?
  In-Reply-To: <548614C8.90203@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox