From: digoal@126.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14163: Index only scan Buffer read enlarged when the data is random
Date: Sat, 28 May 2016 16:09:41 +0000
Message-ID: <20160528160941.19432.17678@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: 14163
Logged by: Zhou Digoal
Email address: digoal@126.com
PostgreSQL version: 9.6beta1
Operating system: CentOS 6.x x64
Description:
postgres=# create table tbl7(id int primary key, info text);
CREATE TABLE
postgres=# insert into tbl7 select trunc(random()*10000000),
md5(random()::text) from generate_series(1,5000000) on conflict on
constraint tbl7_pkey do nothing;
INSERT 0 3934548
postgres=# vacuum analyze tbl7;
VACUUM
postgres=# set enable_seqscan=off;
SET
postgres=# explain (analyze,buffers,costs,timing,verbose) select id from
tbl7;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
Index Only Scan using tbl7_pkey on public.tbl7 (cost=0.43..73176.63
rows=3934547 width=4) (actual time=0.047..969.841 rows=3934548 loops=1)
Output: id
Heap Fetches: 0
Buffers: shared hit=41790
Planning time: 0.055 ms
Execution time: 1686.971 ms
(6 rows)
postgres=# select relpages from pg_class where relname='tbl7_pkey';
relpages
----------
14158
(1 row)
when i cluster it or load it to another table ordered.
the seq scan only scan 10755 pages.
it's a bug or we can optimized it?
postgres=# create table tbl8(id int primary key, info text);
CREATE TABLE
postgres=# insert into tbl8 select * from tbl7 order by id;
INSERT 0 3934548
postgres=# vacuum analyze tbl8;
VACUUM
postgres=# select relpages from pg_class where relname='tbl8_pkey';
relpages
----------
10791
(1 row)
postgres=# explain (analyze,buffers,costs,timing,verbose) select id from
tbl8;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
Index Only Scan using tbl8_pkey on public.tbl8 (cost=0.43..69809.63
rows=3934547 width=4) (actual time=0.026..921.137 rows=3934548 loops=1)
Output: id
Heap Fetches: 0
Buffers: shared hit=10755
Planning time: 0.111 ms
Execution time: 1626.908 ms
(6 rows)
best regards ,
digoal
--
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 #14163: Index only scan Buffer read enlarged when the data is random
In-Reply-To: <20160528160941.19432.17678@wrigleys.postgresql.org>
References: <20160528160941.19432.17678@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