Re: Slow count(*)

Поиск
Список
Период
Сортировка
От Andrew Sullivan
Тема Re: Slow count(*)
Дата
Msg-id 20080102162539.GU22706@crankycanuck.ca
обсуждение исходный текст
Ответ на Slow count(*)  ("Abraham, Danny" <danny_abraham@bmc.com>)
Список pgsql-hackers
On Wed, Jan 02, 2008 at 09:29:24AM -0600, Abraham, Danny wrote:
> We are looking for a patch that will help us  count using the indexes.

Is this for 
SELECT count(*) FROM table;
or 
SELECT count(1) FROM table WHERE. . .
The latter _will_ use an index, if the index is correct, the statistics are
right, and the index selectivity is worth the cost of reading the index. 
The former will not use an index at all, because the answer depends on
visibility, and you can't know that without reading the table.  If you're
counting how many rows are in the table (for, for instance, display
purposes), you probably need to do something else.

> Our product is about 20 times slower on Postgres compared to MS SQL
> Server.
> 
> Any ideas?

Not without the queries, the EXPLAIN ANALYZE plans, and some information
about the database.

A


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

Предыдущее
От: "Brian Modra"
Дата:
Сообщение: Index performance
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: Index performance