Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XzXhE-0007Tz-1i for pgsql-performance@arkaria.postgresql.org; Fri, 12 Dec 2014 21:24:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XzXhC-0000c4-Ne for pgsql-performance@arkaria.postgresql.org; Fri, 12 Dec 2014 21:24:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XzXhA-0000Xs-Cb; Fri, 12 Dec 2014 21:24:16 +0000 Received: from 01.zmailcloud.com ([192.198.85.104] helo=mx-out-1.zmailcloud.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XzXh5-00043n-JQ; Fri, 12 Dec 2014 21:24:15 +0000 Received: from smtp.01.com (smtp.01.com [10.10.0.43]) by mx-out-1.zmailcloud.com (Postfix) with ESMTP id 5A990567640; Fri, 12 Dec 2014 15:24:10 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 497846033C; Fri, 12 Dec 2014 15:24:10 -0600 (CST) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5nKY3Ol2z5Qa; Fri, 12 Dec 2014 15:24:10 -0600 (CST) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 25C0760399; Fri, 12 Dec 2014 15:24:10 -0600 (CST) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 049166033C; Fri, 12 Dec 2014 15:24:10 -0600 (CST) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id by0OV8CNV4rH; Fri, 12 Dec 2014 15:24:09 -0600 (CST) Received: from [172.47.23.103] (50-0-89-106.dsl.dynamic.fusionbroadband.com [50.0.89.106]) by smtp-out-2.01.com (Postfix) with ESMTPSA id BA8F1603A6; Fri, 12 Dec 2014 15:24:07 -0600 (CST) Message-ID: <548B5CF4.4030009@agliodbs.com> Date: Fri, 12 Dec 2014 13:24:04 -0800 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Tim Dudgeon CC: pgsql-sql@postgresql.org, pgsql-performance@postgresql.org Subject: Re: Re: [SQL] querying with index on jsonb slower than standard column. Why? 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> <548614C8.90203@aklaver.com> <54861A81.8030509@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance