index-only-scan when there is an index on all columns

From: Hadi Moshayedi <hadi(at)moshayedi(dot)net>
To: pgsql-general List <pgsql-general(at)postgresql(dot)org>
Cc: Hadi Moshayedi <hadi(at)citusdata(dot)com>
Subject: index-only-scan when there is an index on all columns
Date: 2018-02-27 20:37:28
Message-ID: CAK=1=WoPRg73p4EQzNe+i+ctwcu46qB6GQ2yAB5vHc8gfJxZNQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

With the following definition:

create table t1 (a int, b int, c int);
create index on t1 (a,b,c);

I get the following plan for the following query:

postgres=# explain select sum(c) from t1 where a > 0;
QUERY
PLAN
-----------------------------------------------------------------------------------
Aggregate (cost=29.62..29.63 rows=1 width=8)
-> Bitmap Heap Scan on t1 (cost=9.42..27.92 rows=680 width=4)
Recheck Cond: (a > 0)
-> Bitmap Index Scan on t1_a_b_c_idx (cost=0.00..9.25 rows=680
width=0)
Index Cond: (a > 0)
(5 rows)

I am wondering why is it not using index-only-scan (which would use the
cache better) and instead it does a bitmap scan?

Thanks,
Hadi

Browse pgsql-general by date

  From Date Subject
Next Message Hadi Moshayedi 2018-02-27 20:49:17 index-only-scan when there is an index on all columns
Previous Message Joe Conway 2018-02-27 20:33:46 Re: selecting timestamp