Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XaAN1-0004MN-Ur for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Oct 2014 21:26:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XaAN1-0001mH-B6 for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Oct 2014 21:26:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xa4bT-00020j-Hc for pgsql-bugs@postgresql.org; Fri, 03 Oct 2014 15:17:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xa4bP-0000Un-MI for pgsql-bugs@postgresql.org; Fri, 03 Oct 2014 15:17:05 +0000 MIME-Version: 1.0 Subject: BUG #11559: ANY array filters should make use of GIN indexes To: pgsql-bugs@postgresql.org From: rafal@conjur.net Date: Fri, 03 Oct 2014 15:16:26 +0000 Message-ID: <20141003151626.1666.24873@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 11559 Logged by: Rafal Rzepecki Email address: rafal@conjur.net PostgreSQL version: 9.3.5 Operating system: Linux Description: 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? -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs