Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XagIC-0003KT-2h for pgsql-bugs@arkaria.postgresql.org; Sun, 05 Oct 2014 07:31:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XagIA-000459-Uq for pgsql-bugs@arkaria.postgresql.org; Sun, 05 Oct 2014 07:31:42 +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 1XagI9-00044t-Uj for pgsql-bugs@postgresql.org; Sun, 05 Oct 2014 07:31:42 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XagI1-0007rw-7V for pgsql-bugs@postgresql.org; Sun, 05 Oct 2014 07:31:39 +0000 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id C89D5288C8; Sun, 5 Oct 2014 00:31:30 -0700 (PDT) Received: from EX13-CAS-004.vmware.com (EX13-CAS-004.vmware.com [10.113.191.54]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id C414E410BD; Sun, 5 Oct 2014 00:31:30 -0700 (PDT) Received: from EX13-MBX-024.vmware.com (10.113.191.44) by EX13-MBX-012.vmware.com (10.113.191.32) with Microsoft SMTP Server (TLS) id 15.0.775.38; Sun, 5 Oct 2014 00:31:30 -0700 Received: from [192.168.1.90] (10.113.160.246) by EX13-MBX-024.vmware.com (10.113.191.44) with Microsoft SMTP Server (TLS) id 15.0.775.38; Sun, 5 Oct 2014 00:31:29 -0700 Message-ID: <5430F3CE.6070603@vmware.com> Date: Sun, 5 Oct 2014 10:31:26 +0300 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.0 MIME-Version: 1.0 To: , Subject: Re: BUG #11559: ANY array filters should make use of GIN indexes References: <20141003151626.1666.24873@wrigleys.postgresql.org> In-Reply-To: <20141003151626.1666.24873@wrigleys.postgresql.org> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.113.160.246] X-ClientProxiedBy: EX13-CAS-013.vmware.com (10.113.191.65) To EX13-MBX-024.vmware.com (10.113.191.44) X-Pg-Spam-Score: -6.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 On 10/03/2014 06:16 PM, rafal@conjur.net wrote: > Consider schema: > > create table arr_test(strs text[]); > insert into arr_test select array[i, i+1] from generate_series(1, 1000) i; > create index strs_idx on arr_test using gin(strs); > > In this schema, query > > select * from arr_test where '2' = any(strs); > > yields a plan > > QUERY PLAN > ---------------------------------------------------------- > Seq Scan on arr_test (cost=0.00..31.50 rows=2 width=37) > Filter: ('2'::text = ANY (strs)) > > yet (AFAICT) equivalent query > > select * from arr_test where array['2'] && strs; > > uses the index: > > QUERY PLAN > ----------------------------------------------------------------------- > Bitmap Heap Scan on arr_test (cost=8.02..13.21 rows=2 width=37) > Recheck Cond: ('{2}'::text[] && strs) > -> Bitmap Index Scan on strs_idx (cost=0.00..8.02 rows=2 width=0) > Index Cond: ('{2}'::text[] && strs) > > In one of our databases with ~150k rows this makes for a difference in > speed of four orders of magnitude. > > > Is it possible to have the optimizer automatically use index for ANY queries > like that? Or are these queries inequivalent in some non-straightforward > manner? I think the queries are indeed equivalent. The planner just isn't smart enough to do the transformation automatically. (this is not a bug, just a missing feature) - Heikki -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs