Re: Faster 'select count(*) from table' ?

Поиск
Список
Период
Сортировка
От scott.marlowe
Тема Re: Faster 'select count(*) from table' ?
Дата
Msg-id Pine.LNX.4.33.0302251619480.16809-100000@css120.ihs.com
обсуждение исходный текст
Ответ на Faster 'select count(*) from table' ?  (Matt Mello <alien@spaceship.com>)
Список pgsql-performance
On Tue, 25 Feb 2003, Matt Mello wrote:

> Does anyone know if there is a fast way to find out how many records are
> in a table?
>
> "Select count(*) from table" is very slow.
>
> I would think that PG would keep up with the number of undeleted rows on
> a realtime basis.  Is that the case?  If so, how would I query it?

Sorry, it doesn't, and it's one of the areas that having an MVCC style
database costs you.  Also, if postgresql kept up with this automatically,
it would have an overhead for each table, but how often do you use it on
ALL your tables?  Most the time, folks use count(*) on a few tables only,
and it would be a waste to have a seperate counting mechanism for all
tables when you'd only need it for a few.

The general mailing list has several postings in the last 12 months about
how to setup a trigger to a single row table that keeps the current
count(*) of the master table.

If you need a rough count, you can get one from the statistics gathered by
analyze in the pg_* tables.


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

Предыдущее
От: Matt Mello
Дата:
Сообщение: Faster 'select count(*) from table' ?
Следующее
От: Anuradha Ratnaweera
Дата:
Сообщение: Re: Superfluous merge/sort