From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: rafal@conjur.net
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #11559: ANY array filters should make use of GIN indexes
Date: Sun, 5 Oct 2014 10:31:26 +0300
Message-ID: <5430F3CE.6070603@vmware.com> (raw)
In-Reply-To: <20141003151626.1666.24873@wrigleys.postgresql.org>
References: <20141003151626.1666.24873@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: hlinnakangas@vmware.com, rafal@conjur.net
Subject: Re: BUG #11559: ANY array filters should make use of GIN indexes
In-Reply-To: <5430F3CE.6070603@vmware.com>
References: <20141003151626.1666.24873@wrigleys.postgresql.org> <5430F3CE.6070603@vmware.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox