From: digoal@126.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14129: Why GIN index not use index scan?
Date: Sat, 07 May 2016 14:53:02 +0000
Message-ID: <20160507145302.2680.33288@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 14129
Logged by: digoal
Email address: digoal@126.com
PostgreSQL version: 9.5.2
Operating system: CentOS 6.x x64
Description:
In some case , people will use limit get data, or use cursor get data.
bitmap scan not very good for these use case, because it must sort all
matched ctid first.
GIN index implement bitmap index scan only?
why not let's gin index can use index scan?
This is test case:
```
postgres=# create table t3(id int, info int[]);
CREATE TABLE
postgres=# insert into t3 select generate_series(1,10000),array[1,2,3,4,5];
INSERT 0 10000
postgres=# create index idx_t3_info on t3 using gin(info);
CREATE INDEX
postgres=# set enable_seqscan=off;
SET
```
get all data it's good.
postgres=# explain analyze select * from t3 where info && array [1] ;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on t3 (cost=83.00..302.00 rows=10000 width=45) (actual
time=1.156..3.565 rows=10000 loops=1)
Recheck Cond: (info && '{1}'::integer[])
Heap Blocks: exact=94
-> Bitmap Index Scan on idx_t3_info (cost=0.00..80.50 rows=10000
width=0) (actual time=1.129..1.129 rows=10000 loops=1)
Index Cond: (info && '{1}'::integer[])
Planning time: 0.107 ms
Execution time: 5.272 ms
(7 rows)
but get small data , it's not good. ctid sort waste resource.
postgres=# explain analyze select * from t3 where info && array [1] limit
1;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------
Limit (cost=83.00..83.02 rows=1 width=45) (actual time=1.121..1.121 rows=1
loops=1)
-> Bitmap Heap Scan on t3 (cost=83.00..302.00 rows=10000 width=45)
(actual time=1.119..1.119 rows=1 loops=1)
Recheck Cond: (info && '{1}'::integer[])
Heap Blocks: exact=1
-> Bitmap Index Scan on idx_t3_info (cost=0.00..80.50 rows=10000
width=0) (actual time=1.095..1.095 rows=10000 loops=1)
Index Cond: (info && '{1}'::integer[])
Planning time: 0.113 ms
Execution time: 1.175 ms
(8 rows)
--
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: digoal@126.com
Subject: Re: BUG #14129: Why GIN index not use index scan?
In-Reply-To: <20160507145302.2680.33288@wrigleys.postgresql.org>
References: <20160507145302.2680.33288@wrigleys.postgresql.org>
* 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