Re: COUNT(*) and index-only scans - Mailing list pgsql-hackers

From Robert Haas
Subject Re: COUNT(*) and index-only scans
Date
Msg-id CA+TgmoaOT4xenvZQgBeUAuefn12QV_od5WPYQ+CVJPHo9MSYsw@mail.gmail.com
Whole thread Raw
In response to Re: COUNT(*) and index-only scans  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
List pgsql-hackers
On Mon, Oct 10, 2011 at 3:15 PM, Kevin Grittner
<Kevin.Grittner@wicourts.gov> wrote:
> Robert Haas <robertmhaas@gmail.com> wrote:
>
>> Right now, our costing model for index-only scans is pretty dumb.
>> It assumes that using an index-only scan will avoid 10% of the
>> heap fetches.  That could easily be low, and on an insert-only
>> table or one where only the recently-updated rows are routinely
>> accessed, it could also be high.
>
> As a reality check, I just ran this query on a table in a statewide
> copy of our data:
>
> select count(*),
>  sum(case when xmin = '2'::xid then 0 else 1 end) as read_heap
>  from "CaseHist";
>
> and got:
>
>   count   | read_heap
> -----------+-----------
>  205765311 |   3934924
>
> So on our real-world database, it would skip something on the order
> of 98% of the heap reads, right?

Yeah, if it's scanning the whole table.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: index-only scans
Next
From: Robert Haas
Date:
Subject: Re: table/index options | was: COUNT(*) and index-only scans