Re: 9.2 and index only scans

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: 9.2 and index only scans
Date: 2012-08-28 08:02:12
Message-ID: 20120828080212.GB15432@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mark Morgan Lloyd 2012-08-28 09:07:45 Re: Looking for ODBC drivers for NT4.
Previous Message Tom Lane 2012-08-27 23:28:37 Re: Documentation of Implicit Function Call /w Composite Types