Question about index scan vs seq scan when using count() - Mailing list pgsql-sql

From Kashmira Patel \(kupatel\)
Subject Question about index scan vs seq scan when using count()
Date
Msg-id 18AE59788A3FC640A367E5652E664D800199BEA7@xmb-sjc-237.amer.cisco.com
Whole thread Raw
Responses Re: Question about index scan vs seq scan when using count()
List pgsql-sql
Hello,
   I am using postgres version 7.4, and I read this in the documentation:
 
"The aggregate functions sum and count always require a sequential scan if applied to the entire table."
 
My understanding of this statement is that if I use count() without a WHERE clause, then essentially, it is applied to the entire table and hence requires a seq scan.
But it should not require a seq scan if I have a condition.
 
For example: I have a table vm_message with an index on column msgid.
Will the following do a sequential scan or an index?
 
select count(*) from vm_message where msgid = 3;
 
I used explain, and it said it would do a sequential scan. Why is that?
In fact explain select * from vm_message where msgid = 3 also did a sequential scan.
 
What am I doing wrong here? I want it to use my index.
 
Thanks,
Kashmira

pgsql-sql by date:

Previous
From: Mario Splivalo
Date:
Subject: Re: 'locking' the SELECTs based on indices...
Next
From: Andrew Sullivan
Date:
Subject: Re: Question about index scan vs seq scan when using count()