Re: select count... - Mailing list pgsql-hackers

From Doug McNaught
Subject Re: select count...
Date
Msg-id m3n169x93g.fsf@belphigor.mcnaught.org
Whole thread Raw
In response to select count...  ("P. Dwayne Miller" <dmiller@espgroup.net>)
List pgsql-hackers
"P. Dwayne Miller" <dmiller@espgroup.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


pgsql-hackers by date:

Previous
From: mlw
Date:
Subject: Re: AW: Re: SOMAXCONN (was Re: Solaris source code)
Next
From: "P. Dwayne Miller"
Date:
Subject: Re: select count...