Re: Why count(*) doest use index?

From: Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>
To: Allan Kamau <kamauallan(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, John R Pierce <pierce(at)hogranch(dot)com>
Subject: Re: Why count(*) doest use index?
Date: 2011-03-06 10:45:07
Message-ID: 1B34B94E-1A19-400C-9BCE-627227420760@solfertje.student.utwente.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6 Mar 2011, at 9:03, Allan Kamau wrote:

> If this is true it seems that the primary key and perhaps other unique
> indexes do indeed contain exact details of the uniqueness of the
> persisted tuples of a given relation at any given time.

That is true within a single transaction, but indexes contain information about ALL active transactions. Because of that the contents of the indexes are not guaranteed to be unique and it's possible they contain references to rows that are not visible to the current transaction.

> Or am I missing a crucial point.

Yup, you're missing the effects of concurrency.

Alban Hertroys

--
If you can't see the forest for the trees,
cut the trees and you'll see there is no forest.

!DSPAM:737,4d7365c5235885600661482!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alexander Farber 2011-03-06 13:43:32 Copying few tables from one database to another
Previous Message Martijn van Oosterhout 2011-03-06 10:41:14 Re: Why count(*) doest use index?