Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WXuBR-00059U-U4 for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Apr 2014 15:13:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WXuBR-0008Vb-B1 for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Apr 2014 15:13:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WXuBQ-0008VT-An for pgsql-hackers@postgresql.org; Wed, 09 Apr 2014 15:13:00 +0000 Received: from mail-qa0-x22f.google.com ([2607:f8b0:400d:c00::22f]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WXuBJ-0002Op-BT for pgsql-hackers@postgresql.org; Wed, 09 Apr 2014 15:13:00 +0000 Received: by mail-qa0-f47.google.com with SMTP id m5so559757qaj.20 for ; Wed, 09 Apr 2014 08:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=JrGEy6gq8xHQnQm0BZ2irmBXDWt+TnehZTe1EgYDN/0=; b=hSN60p91DmGYcRV/0kuu5Rv6pPUjcoJAbeqwBYbLiWyqIQBkJiLWsYzoM9b8gM1+tl 5TduANRym3N5XE2YqFl1ciP8Y2umacPxqCwI6/t3+rO3HpDsnNSLqeXKKnl8IwwxMwFh sqXSv4LLPoM9+uSfCMEGVFjMC14lILToc4k4jBS9K9YxDi6594Qdefz0O+HTAop36Quh gcjA9n1tJr7jm4red3duMT1o9Zx8fjb/h4F167pjUiCQMDsHtqsreTDi1MIRIVekP1cL uHhKk2lxMbWgcEFe8QiRzs0g/bnR2lyy9TljzwMKARLsRebYtTTv9F/q1zjACB2uQ2XC orcA== X-Received: by 10.140.87.151 with SMTP id r23mr12366419qgd.75.1397056371752; Wed, 09 Apr 2014 08:12:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.75.201 with HTTP; Wed, 9 Apr 2014 08:12:31 -0700 (PDT) In-Reply-To: References: <27299.1396989666@sss.pgh.pa.us> <28589.1396992841@sss.pgh.pa.us> <29030.1396993582@sss.pgh.pa.us> <534475B7.6020908@dunslane.net> <5344EAA4.1050605@vmware.com> <53450306.8040104@vmware.com> From: Alexander Korotkov Date: Wed, 9 Apr 2014 19:12:31 +0400 Message-ID: Subject: Re: default opclass for jsonb (was Re: Call for GIST/GIN/SP-GIST opclass documentation) To: Peter Geoghegan Cc: Heikki Linnakangas , Andrew Dunstan , Tom Lane , pgsql-hackers Content-Type: multipart/alternative; boundary=001a11c13d64c50bf704f69d8880 X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --001a11c13d64c50bf704f69d8880 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Apr 9, 2014 at 12:40 PM, Peter Geoghegan wrote: > On Wed, Apr 9, 2014 at 1:21 AM, Heikki Linnakangas > wrote: > > I didn't say that. On the contrary, I think the shotgun approach > jsonb_ops > > and jsonb_hash_ops take is too broad. It should be possible to specify > what > > to index in a more detailed fashion. > > It is - use an expression index. That's by far the most important way > to specify what to index in a more detailed fashion. There are others, > but that's the major one. Beyond that, yes, it's necessary to > carefully write your query predicate a certain way. However, a similar > situation exists in MongoDB, where there is a distinction between > "Indexes on embedded fields" (which must be accessed using special > "dot notation") and "indexes on subdocuments" (which cannot be > accessed using "dot notation"). It's late here, but I'm pretty sure > that's a feature and not a limitation. > I believe that serious limitation we now have is that we actually specify kind of index to be used in the SQL query. For example you need to find objects with active = true. You can write: js @> {"active": true} then GIN index on js can be used. Also you can write: js->'active' = true then btree expression index on (js->'active') can be used. For sure, one can do js @> {"active": true} AND js->'active' = true This query can use any of indexes, but it is: 1) Cluge 2) Excess recheck 3) If both indexes present, excess "bitmap and". Having to choose index in SQL-query we make our SQL more imperative and less declarative. Similar things can happen without json/hstore (user have to rewrite SQL in order to use expression index), but now it could become very common. My opinion is that we have to do something in planner to make it understand at least this two kinds of queries to be equivalent. ------ With best regards, Alexander Korotkov. --001a11c13d64c50bf704f69d8880 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On W= ed, Apr 9, 2014 at 12:40 PM, Peter Geoghegan <pg@heroku.com> wr= ote:
On Wed, Apr 9, 2014 at 1:21 AM, Heikki Linnakangas
<hlinnakangas@vmware.com&= gt; wrote:
> I didn't say that. On the contrary, I think the shotgun approach j= sonb_ops
> and jsonb_hash_ops take is too broad. It should be possible to specify= what
> to index in a more detailed fashion.

It is - use an expression index. That's by far the most important= way
to specify what to index in a more detailed fashion. There are others,
but that's the major one. Beyond that, yes, it's necessary to
carefully write your query predicate a certain way. However, a similar
situation exists in MongoDB, where there is a distinction between
"Indexes on embedded fields" (which must be accessed using specia= l
"dot notation") and "indexes on subdocuments" (which ca= nnot be
accessed using "dot notation"). It's late here, but I'm p= retty sure
that's a feature and not a limitation.

<= div>I believe that serious limitation we now have is that we actually speci= fy kind of index to be used in the SQL query.=A0
For example you need to= find objects with active =3D true. You can write:

js @> {"active": true}

<= /div>
then GIN index on js can be used. Also you can write:

js->'active' =3D true

then btree expression index on (js->'active') can be used. For s= ure, one can do

js @> {"active": true= } AND js->'active' =3D true

This qu= ery can use any of indexes, but it is:
1) Cluge
2) Excess recheck
3) If both indexes pres= ent, excess "bitmap and".

Having to choo= se index in SQL-query we make our SQL more imperative and less declarative.= Similar things can happen without json/hstore (user have to rewrite SQL in= order to use expression index), but now it could become very common. My op= inion is that we have to do something in planner to make it understand at l= east this two kinds of queries to be equivalent.

------
With best regards,
Alexander Korotkov.
=A0<= /div>
--001a11c13d64c50bf704f69d8880--