Question about index scan vs seq scan when using count()

Поиск
Список
Период
Сортировка
От Kashmira Patel \(kupatel\)
Тема Question about index scan vs seq scan when using count()
Дата
Msg-id 18AE59788A3FC640A367E5652E664D800199BEA7@xmb-sjc-237.amer.cisco.com
обсуждение исходный текст
Ответы Re: Question about index scan vs seq scan when using count()
Список 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 по дате отправления:

Предыдущее
От: Mario Splivalo
Дата:
Сообщение: Re: 'locking' the SELECTs based on indices...
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: Question about index scan vs seq scan when using count()