Re: Why count(*) doest use index?

Поиск
Список
Период
Сортировка
От Raymond O'Donnell
Тема Re: Why count(*) doest use index?
Дата
Msg-id 4D726CAB.8040503@iol.ie
обсуждение исходный текст
Ответ на Why count(*) doest use index?  (<obamabarak@e1.ru>)
Ответы Re: Why count(*) doest use index?  (Allan Kamau <kamauallan@gmail.com>)
Список pgsql-general
On 03/03/2011 13:29, obamabarak@e1.ru wrote:
> I use pgsql 9.0.3 and I know that postgresql tries to use the fields in
> indexes instead of the original table if it possible
>
> But when I run
>
> SELECT COUNT(id) FROM tab
>
> or
>
> SELECT COUNT(*) FROM tab
>
> where there "id" is PRIMARY KEY and there are other indexes there I get
> execution plan that doesnt use any indexes, but sequentab scanning the
> original table.

Because when you do SELECT COUNT(*) without any WHERE.... clause, then
PostgreSQL has to scan through *all* the rows in the table in order to
count them.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

В списке pgsql-general по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: PHP array to PlPgSQL arrat. How to?
Следующее
От: Dmitriy Igrishin
Дата:
Сообщение: Re: PHP array to PlPgSQL arrat. How to?