pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: digoal@126.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14253: b-tree no index range scan?
Date: Sun, 17 Jul 2016 03:03:16 +0000
Message-ID: <20160717030316.1425.90322@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:      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


view thread (2+ messages)  latest in thread

Message-ID: <20160717030316.1425.90322@wrigleys.postgresql.org>
Permalink:  ../20160717030316.1425.90322@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160717030316.1425.90322@wrigleys.postgresql.org

 · 

reply

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 #14253: b-tree no index range scan?
  In-Reply-To: <20160717030316.1425.90322@wrigleys.postgresql.org>
  References: <20160717030316.1425.90322@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