pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #11559: ANY array filters should make use of GIN indexes
2+ messages / 2 participants
[nested] [flat]
* BUG #11559: ANY array filters should make use of GIN indexes
@ 2014-10-03 15:16 rafal@conjur.net
0 siblings, 1 reply; 2+ messages in thread
From: rafal@conjur.net @ 2014-10-03 15:16 UTC (permalink / raw)
To: pgsql-bugs
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #11559: ANY array filters should make use of GIN indexes
@ 2014-10-05 07:31 Heikki Linnakangas <hlinnakangas@vmware.com>
parent: rafal@conjur.net
0 siblings, 0 replies; 2+ messages in thread
From: Heikki Linnakangas @ 2014-10-05 07:31 UTC (permalink / raw)
To: rafal@conjur.net; pgsql-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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2014-10-05 07:31 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-10-03 15:16 BUG #11559: ANY array filters should make use of GIN indexes rafal@conjur.net
2014-10-05 07:31 ` Heikki Linnakangas <hlinnakangas@vmware.com>
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