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

From Aidan Van Dyk
Subject Re: COUNT(*) and index-only scans
Date
Msg-id CAC_2qU9t0rqWGRrJsMH44FO44RE0uAmSBwVeXPEJqiuojuuA9Q@mail.gmail.com
Whole thread Raw
In response to Re: COUNT(*) and index-only scans  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: COUNT(*) and index-only scans
Re: COUNT(*) and index-only scans
List pgsql-hackers
On Wed, Oct 12, 2011 at 10:37 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> - Suppose the table has a million rows and we're going to read 100 of
>> them, or 0.01%.  Now it might appear that a covering index has a
>> negligible advantage over a non-covering index, but in fact I think we
>> still want to err on the side of trying to use the covering index.
>
> Given that fact pattern we still will, I think.  We'll still prefer an
> indexscan over a seqscan, for sure.  In any case, if you believe the
> assumption that those 100 rows are more likely to be recently-dirtied
> than the average row, I'm not sure why you think we should be trying to
> force an assumption that index-only will succeed here.

The elephant in the room is that the index-only-scan really doesn't
save a *whole* lot if the heap pages are already in shared buffers.
But it matters a *lot* when they heap pages are not in shared buffers
(both ways, saving IO, or causing lots of random IO)

Can we hope that if pages are not in shared buffers, they are not
recently modified, so hopefully both all visible, and have the VM
bit?set?  Or does the table-based nature of vacuum mean there is no
value there?

--
Aidan Van Dyk                                             Create like a god,
aidan@highrise.ca                                       command like a king,
http://www.highrise.ca/                                   work like a slave.


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [BUGS] *.sql contrib files contain unresolvable MODULE_PATHNAME
Next
From: Greg Stark
Date:
Subject: Re: COUNT(*) and index-only scans