Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XzbO3-000778-IO for pgsql-performance@arkaria.postgresql.org; Sat, 13 Dec 2014 01:20:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XzbO3-0005We-2z for pgsql-performance@arkaria.postgresql.org; Sat, 13 Dec 2014 01:20:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XzbO1-0005WT-Sl; Sat, 13 Dec 2014 01:20:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XzbNz-0003US-1P; Sat, 13 Dec 2014 01:20:44 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id sBD1Kb1B015864; Fri, 12 Dec 2014 20:20:37 -0500 From: Tom Lane To: Andrew Dunstan cc: Josh Berkus , Tim Dudgeon , pgsql-sql@postgresql.org, pgsql-performance@postgresql.org Subject: Re: Re: [SQL] querying with index on jsonb slower than standard column. Why? In-reply-to: <548B79E3.5070301@dunslane.net> 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> <548B5CF4.4030009@agliodbs.com> <8867.1418420650@sss.pgh.pa.us> <548B79E3.5070301@dunslane.net> Comments: In-reply-to Andrew Dunstan message dated "Fri, 12 Dec 2014 18:27:31 -0500" Date: Fri, 12 Dec 2014 20:20:37 -0500 Message-ID: <15863.1418433637@sss.pgh.pa.us> 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 Andrew Dunstan writes: > On 12/12/2014 04:44 PM, Tom Lane wrote: >> Well, it'd be easy to fix if we were willing to invent distinct operators >> depending on which type you wanted out (perhaps ->> for text output as >> today, add ->># for numeric output, etc). > That was my immediate reaction. Not sure about the operator name. I'd > tentatively suggest -># (taking an int or text argument) and #># taking > a text[] argument, both returning numeric, and erroring out if the value > is a string, boolean, object or array. >> The usability issue could be fixed by teaching the planner to fold a >> construct like (jsonb ->> 'foo')::numeric into (jsonb ->># 'foo'). >> But I'm not sure how we do that except in a really ugly and ad-hoc >> fashion. > I would be inclined to add the operator and see how cumbersome people > find it. I suspect in many cases it might be sufficient. We can't just add the operator and worry about usability later; if we're thinking we might want to introduce such an automatic transformation, we have to be sure the new operator is defined in a way that allows the transformation to not change any semantics. What that means in this case is that if (jsonb ->> 'foo')::numeric would have succeeded, (jsonb ->># 'foo') has to succeed; which means it'd better be willing to attempt conversion of string values to numeric, not just throw an error on sight. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance