Re: Why Select Count(*) from table - took over 20 minutes? - Mailing list pgsql-general

From Jasen Betts
Subject Re: Why Select Count(*) from table - took over 20 minutes?
Date
Msg-id iarcnr$sp4$1@reversiblemaps.ath.cx
Whole thread Raw
In response to what can depend on index  (Szymon Guz <mabewlun@gmail.com>)
List pgsql-general
On 2010-10-26, John R Pierce <pierce@hogranch.com> wrote:
>
> count(*) has to read the whole table to get the accurate count.   The
> reason for this is that different clients can see different versions of
> that table, for instance, if client A is already in a transaction, and
> client B then does an INSERT, the two clients will see different values
> for the count.

They may or may not. the default transaction isolation level "read commited"
allows a session to see most changes that were committed externally after the
start of the transaction.

Tlso the index may include deleted rows.
which is another reason count(*) does a table scan.

--
ɹǝpun uʍop ɯoɹɟ sƃuıʇǝǝɹ⅁


pgsql-general by date:

Previous
From: Dimitri Fontaine
Date:
Subject: Re: Group by and limit
Next
From: Gerrit Seré
Date:
Subject: Compiling PostgreSql 9.0 on Sparc Solaris (64 bit)