Re: 9.2 and index only scans - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: 9.2 and index only scans
Date
Msg-id 20120828080212.GB15432@svana.org
Whole thread Raw
In response to Re: 9.2 and index only scans  (Thomas Kellerer <spam_eater@gmx.net>)
Responses Re: 9.2 and index only scans  (Thomas Kellerer <spam_eater@gmx.net>)
List pgsql-general
On Sun, Aug 26, 2012 at 11:01:31PM +0200, Thomas Kellerer wrote:
> I was inspired by this question on StackOverflow:
> http://stackoverflow.com/questions/12128501/fastest-way-to-count-the-rows-in-any-database-table/12128545#12128545
>
> Which shows Oracle's behaviour with an index scan for the count(*) operation.

Interesting, It shows indeed Oracle uses the index to do the operation.

For postgres it's not so simple for a few reasons, I'm not sure how
oracle avoids the same issues:

- The index has no visibility information, so you can't tell if an
  index entry refers to a row you can actually see in your session.
  The visibility map might help here in the future.

- Different versions of the same row (after an UPDATE for example) may
  both be in the index, Now if you're counting a primary key column you
  can work around that.

But frankly, counting all the rows in a table is something I never do.
The system tables carry estimates which have proved good enough for
statistical purposes when I need them.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> He who writes carelessly confesses thereby at the very outset that he does
> not attach much importance to his own thoughts.
   -- Arthur Schopenhauer

Attachment

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Documentation of Implicit Function Call /w Composite Types
Next
From: Mark Morgan Lloyd
Date:
Subject: Re: Looking for ODBC drivers for NT4.