Re: select count...

From: Doug McNaught <doug(at)wireboard(dot)com>
To: "P(dot) Dwayne Miller" <dmiller(at)espgroup(dot)net>
Cc: PostgreSQL Hackers Newsgroup <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: select count...
Date: 2001-07-13 13:16:35
Message-ID: m3n169x93g.fsf@belphigor.mcnaught.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"P. Dwayne Miller" <dmiller(at)espgroup(dot)net> writes:

> What's the fastest way to select the number of rows in a table? If I
> use count(*) with no whereclause, it uses a seq_scan and takes 4 secs
> (122k rows). With a where clause, it uses an index and returns in < 1
> sec. Selecting count(requestnumber), which is an indexed column, with
> no where clause again takes 4 secs. This latter version, I thought,
> would use the index. The values of requestnumber are very distributed.

Exactly how would you expect to get a count of all the rows in the
table (no WHERE clause) without a sequential scan? I don't see any
problem with the above results.

The only case in which COUNT(requestnumber) might use the index would
be if there were a significant number of NULLs in that column, but you
don't give any information on that.

-Doug
--
The rain man gave me two cures; he said jump right in,
The first was Texas medicine--the second was just railroad gin,
And like a fool I mixed them, and it strangled up my mind,
Now people just get uglier, and I got no sense of time... --Dylan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Martijn van Oosterhout 2001-07-13 13:51:40 [PATCH] To remove EXTEND INDEX
Previous Message mlw 2001-07-13 11:53:02 Re: AW: Re: SOMAXCONN (was Re: Solaris source code)