Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YFyBF-0001Xf-PE for pgsql-bugs@arkaria.postgresql.org; Tue, 27 Jan 2015 04:55:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YFyBE-00088K-F6 for pgsql-bugs@arkaria.postgresql.org; Tue, 27 Jan 2015 04:55:12 +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 1YF4Mk-0002cC-NE for pgsql-bugs@postgresql.org; Sat, 24 Jan 2015 17:19:22 +0000 Received: from mail.mcdee.net ([88.198.61.140] helo=hz1.mcdee.net) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YF4Mg-0002VD-8t for pgsql-bugs@postgresql.org; Sat, 24 Jan 2015 17:19:20 +0000 Received: from localhost (localhost [127.0.0.1]) by hz1.mcdee.net (Postfix) with ESMTP id BE35FE46F9C; Sat, 24 Jan 2015 17:19:14 +0000 (GMT) X-Virus-Scanned: Debian amavisd-new at mcdee.net Received: from hz1.mcdee.net ([127.0.0.1]) by localhost (hz1.mcdee.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Pmytx85pScuZ; Sat, 24 Jan 2015 17:19:11 +0000 (GMT) Received: from [10.0.0.112] (unknown [80.252.112.34]) (using TLSv1 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: jgm@mcdee.net) by hz1.mcdee.net (Postfix) with ESMTPSA id B7BC1E46EF0; Sat, 24 Jan 2015 17:19:11 +0000 (GMT) Message-ID: <54C3D40D.80205@mcdee.net> Date: Sat, 24 Jan 2015 17:19:09 +0000 From: Jim McDonald User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: BUG #12644: Planner fails to use available index with anything other than default operator References: <20150123181759.32669.55573@wrigleys.postgresql.org> <16692.1422111691@sss.pgh.pa.us> In-Reply-To: <16692.1422111691@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="------------080805050905000002040902" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------080805050905000002040902 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 24/01/2015 15:01, Tom Lane wrote: > Jim@mcdee.net writes: >> However I cannot use the '?' operator because I'm accessing the database >> through JDBC and there is no way to escape the '?' character. > Seems to me you need to discuss that problem with the pgsql-jdbc folk. > (I suspect they have some solution already, because operators whose names > contain '?' have been around for a very very long time.) Unfortunately they don't, at least from the last conversations I have seen regarding this. I'll take a look to see if it's simple enough to put some sort of escape in place. > >> Instead I attempted to use the functino which underpins the '?' >> operator, however it is not using the index: > Nope, this doesn't work, never has, and will not in the foreseeable > future. Index access is defined in terms of operators, not other > ways to access the same function; see > http://www.postgresql.org/docs/9.4/static/indexes-opclass.html > > Possibly the Berkeley crew should have done it the other way; > but they didn't, and we're unlikely to try to move that mountain > now. Fair enough. As a workaround in the meantime is it possible to create a custom operator that is recognised as being in the correct family/class so that it will use the index? I attempted to add an operator '###' as a synonym for '?' with the JSONB type but it doesn't pick up the index either: CREATE OPERATOR ### ( PROCEDURE = jsonb_exists, LEFTARG = jsonb, RIGHTARG = text, RESTRICT = contsel, JOIN = contjoinsel); > > regards, tom lane Cheers, Jim. --------------080805050905000002040902 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 8bit
On 24/01/2015 15:01, Tom Lane wrote:
Jim@mcdee.net writes:

      
However I cannot use the '?' operator because I'm accessing the database
through JDBC and there is no way to escape the '?' character.
Seems to me you need to discuss that problem with the pgsql-jdbc folk.
(I suspect they have some solution already, because operators whose names
contain '?' have been around for a very very long time.)
Unfortunately they don't, at least from the last conversations I have seen regarding this.  I'll take a look to see if it's simple enough to put some sort of escape in place.

Instead I attempted to use the functino which underpins the '?'
operator, however it is not using the index:
Nope, this doesn't work, never has, and will not in the foreseeable
future.  Index access is defined in terms of operators, not other
ways to access the same function; see
http://www.postgresql.org/docs/9.4/static/indexes-opclass.html

Possibly the Berkeley crew should have done it the other way;
but they didn't, and we're unlikely to try to move that mountain
now.
Fair enough.  As a workaround in the meantime is it possible to create a custom operator that is recognised as being in the correct family/class so that it will use the index?  I attempted to add an operator '###' as a synonym for '?' with the JSONB type but it doesn't pick up the index either:

CREATE OPERATOR ### (
  PROCEDURE = jsonb_exists,
  LEFTARG = jsonb,
  RIGHTARG = text,
  RESTRICT = contsel,
  JOIN = contjoinsel);

			regards, tom lane
Cheers,
Jim.
--------------080805050905000002040902--