pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14253: b-tree no index range scan?
2+ messages / 2 participants
[nested] [flat]
* BUG #14253: b-tree no index range scan?
@ 2016-07-17 03:03 digoal@126.com
2016-07-18 17:46 ` Re: BUG #14253: b-tree no index range scan? Jeff Janes <jeff.janes@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: digoal@126.com @ 2016-07-17 03:03 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14253
Logged by: Zhou Digoal
Email address: digoal@126.com
PostgreSQL version: 9.5.3
Operating system: CentOS 6.x x64
Description:
HI,
when i use b-tree scan many tuples(spread index leaf page), there has big
index page scans, larger than the index's real size. why?
is the explain's bug? or PostgreSQL no index range scan?
postgres=# create unlogged table tbl(id int primary key, info text, crt_time
timestamp);
postgres=# insert into tbl select trunc(random()*100000000),'test',now()
from generate_series(1,50000000) on conflict on constraint tbl_pkey do
nothing;
postgres=# vacuum analyze tbl;
索引和heap的pages占用
postgres=# select relpages from pg_class where relname='tbl';
relpages
----------
250600
(1 row)
postgres=# select relpages from pg_class where relname='tbl_pkey';
relpages
----------
107881
(1 row)
i see postgresql has bi-link between index pages, why not use it reduce scan
index pages?
src/include/access/nbtree.h
typedef struct BTPageOpaqueData
{
BlockNumber btpo_prev; /* left sibling, or P_NONE if
leftmost */
BlockNumber btpo_next; /* right sibling, or P_NONE if
rightmost */
union
{
uint32 level; /* tree level --- zero for
leaf pages */
TransactionId xact; /* next transaction ID, if
deleted */
} btpo;
uint16 btpo_flags; /* flag bits, see below */
BTCycleId btpo_cycleid; /* vacuum cycle ID of latest split
*/
} BTPageOpaqueData;
postgres=# explain (analyze,verbose,timing,costs,buffers) select id from tbl
offset 1000000 limit 10;
QUERY
PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=25968.49..25968.75 rows=10 width=4) (actual
time=528.914..528.921 rows=10 loops=1)
Output: id
Buffers: shared hit=750554
-> Index Only Scan using tbl_pkey on public.tbl (cost=0.56..1021687.32
rows=39344184 width=4) (actual time=0.030..347.409 rows=1000010 loops=1)
Output: id
Heap Fetches: 0
Buffers: shared hit=750554
Planning time: 0.083 ms
Execution time: 528.948 ms
(9 rows)
postgres=# explain (analyze,verbose,timing,costs,buffers) select id from tbl
limit 1000010;
QUERY
PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.56..25968.75 rows=1000010 width=4) (actual
time=0.032..736.929 rows=1000010 loops=1)
Output: id
Buffers: shared hit=750554
-> Index Only Scan using tbl_pkey on public.tbl (cost=0.56..1021687.32
rows=39344184 width=4) (actual time=0.031..362.791 rows=1000010 loops=1)
Output: id
Heap Fetches: 0
Buffers: shared hit=750554
Planning time: 0.097 ms
Execution time: 916.256 ms
(9 rows)
thanks,
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #14253: b-tree no index range scan?
2016-07-17 03:03 BUG #14253: b-tree no index range scan? digoal@126.com
@ 2016-07-18 17:46 ` Jeff Janes <jeff.janes@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Janes @ 2016-07-18 17:46 UTC (permalink / raw)
To: 德哥 <digoal@126.com>; +Cc: pgsql-bugs
On Sat, Jul 16, 2016 at 8:03 PM, <digoal@126.com> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14253
> Logged by: Zhou Digoal
> Email address: digoal@126.com
> PostgreSQL version: 9.5.3
> Operating system: CentOS 6.x x64
> Description:
>
> HI,
> when i use b-tree scan many tuples(spread index leaf page), there has big
> index page scans, larger than the index's real size. why?
> is the explain's bug? or PostgreSQL no index range scan?
...
> postgres=# explain (analyze,verbose,timing,costs,buffers) select id from tbl
> offset 1000000 limit 10;
> QUERY
> PLAN
> -----------------------------------------------------------------------------------------------------------------------------------------------------
> Limit (cost=25968.49..25968.75 rows=10 width=4) (actual
> time=528.914..528.921 rows=10 loops=1)
> Output: id
> Buffers: shared hit=750554
> -> Index Only Scan using tbl_pkey on public.tbl (cost=0.56..1021687.32
> rows=39344184 width=4) (actual time=0.030..347.409 rows=1000010 loops=1)
> Output: id
> Heap Fetches: 0
> Buffers: shared hit=750554
For index-only scan, every time two consecutive index tuples point to
a different page in the visibility map, it counts as a buffer read.
That is because the scan maintains a pin on the last used vm page, and
if the next needed one is different it drops the pin on the old page
and takes a pin one on the needed page.
Your table has 4 pages in the vm (on 9.5) and your table heap is
uncorrelated with the index, so there is a 25% chance of each
consecutive pair of index tuples pointing the same vm page and a 75%
of them pointing to different pages. This very closely fits your
observed data.
So, not a bug.
Cheers,
Jeff
--
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:[~2016-07-18 17:46 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-07-17 03:03 BUG #14253: b-tree no index range scan? digoal@126.com
2016-07-18 17:46 ` Jeff Janes <jeff.janes@gmail.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