Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YF97K-00011E-7e for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Jan 2015 22:23:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YF97J-0008LL-7S for pgsql-bugs@arkaria.postgresql.org; Sat, 24 Jan 2015 22:23:45 +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 1YF97H-0008LC-5w for pgsql-bugs@postgresql.org; Sat, 24 Jan 2015 22:23:43 +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 1YF97E-0007yl-2m for pgsql-bugs@postgresql.org; Sat, 24 Jan 2015 22:23:41 +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 t0OMNa6x023434; Sat, 24 Jan 2015 17:23:36 -0500 From: Tom Lane To: Jim McDonald cc: pgsql-bugs@postgresql.org Subject: Re: BUG #12644: Planner fails to use available index with anything other than default operator In-reply-to: <54C3D40D.80205@mcdee.net> References: <20150123181759.32669.55573@wrigleys.postgresql.org> <16692.1422111691@sss.pgh.pa.us> <54C3D40D.80205@mcdee.net> Comments: In-reply-to Jim McDonald message dated "Sat, 24 Jan 2015 17:19:09 +0000" Date: Sat, 24 Jan 2015 17:23:36 -0500 Message-ID: <23433.1422138216@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-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Jim McDonald writes: > On 24/01/2015 15:01, Tom Lane wrote: >> 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 > 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? Not really, I'm afraid. In the abstract maybe you could add such an operator to an existing operator class; but in practice this will fall foul of the unique indexes on pg_amop, which insist that there be at most one operator per strategy per opclass. However, there's more than one way to skin a cat. I think you could probably define such an operator that references an inlineable SQL function that expands to the desired underlying operator, along the lines of create function my_jsonb_exists(jsonb, text) returns bool as 'select $1 ? $2' language sql immutable; create operator ### ( procedure = my_jsonb_exists, ... regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs