Re: Using Index-only scans to speed up count(*)

From: Noah Misch <noah(at)leadboat(dot)com>
To: Gurjeet Singh <gurjeet(at)singh(dot)im>
Cc: PGSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Using Index-only scans to speed up count(*)
Date: 2014-06-07 15:04:10
Message-ID: 20140607150410.GA509883@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Jun 07, 2014 at 08:35:27AM -0400, Gurjeet Singh wrote:
> While reading [1] in context of Postgres Hibernator, I see that
> Mitsuru mentioned one of the ways other RDBMS allows count(*) to be
> driven by an index.
>
> > 'select /*+ INDEX(emp emp_pk) */ count(*) from emp;' to load index blocks
>
> I am not sure if Postgres planner already allows this,

It does:

create table t (c, junk) as select *, repeat('a', 100)
from generate_series(1,10000);
alter table t add primary key (c);
vacuum t;
analyze t;
explain select count(*) from t;

--
Noah Misch
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2014-06-07 17:03:11 Re: PG Manual: Clarifying the repeatable read isolation example
Previous Message Cédric Villemain 2014-06-07 13:22:16 Re: Using Index-only scans to speed up count(*)