Re: performance of count(*)

Поиск
Список
Период
Сортировка
От Andrew Sullivan
Тема Re: performance of count(*)
Дата
Msg-id 20110506195902.GK29489@shinkuro.com
обсуждение исходный текст
Ответ на performance of count(*)  (Scott Ribe <scott_ribe@elevated-dev.com>)
Список pgsql-general
On Fri, May 06, 2011 at 12:45:23PM -0600, Scott Ribe wrote:

> I need to optimize queries that deal with some aggregates regarding
  resource availability. My specific problem is, I think, very closely
  analogous to select count(*)... where...

If the WHERE clause is fairly selective and indexed, that should be
fast.  Not as fast as estimates based on trigger-written values in
another table, of course, but reasonably fast.  So the first order of
business is usually to find or create indexes that will make SELECT on
the same criteria fast.

It's only unqualified "SELECT count(*)" that is slow.  Generally, the
system table is good enough for that, I find.  (Someone: "How long
will this take?"  Me: "There are about 400 million rows to go
through."  Even if you're off by 50 million at that point, it doesn't
matter.)

A

--
Andrew Sullivan
ajs@crankycanuck.ca

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

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: performance of count(*)
Следующее
От: Tony Capobianco
Дата:
Сообщение: pgloader hangs with an invalid filename