Re: Make COUNT(*) Faster?

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: Make COUNT(*) Faster?
Дата
Msg-id 20050708022141.GB3339@winnie.fuhr.org
обсуждение исходный текст
Ответ на Make COUNT(*) Faster?  (Varun Mehta <vmehta@apple.com>)
Список pgsql-sql
On Thu, Jul 07, 2005 at 03:48:39PM -0700, Varun Mehta wrote:
> 
> I've started using PostgreSQL pretty recently, and I am quite  
> disturbed about the performance of a simple SELECT COUNT(*) FROM  
> table.  What should (in my mind) be a nearly instantaneous operation  
> instead takes nearly 700ms in a table with only 87k rows of data!

Speeding up COUNT is on the developers' TODO list, but it's not as
simple as it might seem or it would have been done already.  This
has been brought up many times over the years -- search the archives
to see past discussion.  Words to search for include "MVCC," "index,"
and "visibility."

> If I run an EXPLAIN on this query I can see that it is doing a  
> sequential scan, which seems quite needless, as surely this  
> information is cached in some secret location.

If an estimate will suffice then you could use the table's
pg_class.reltuples value, but beware that it can be rather
out of date.

http://www.postgresql.org/docs/8.0/static/catalog-pg-class.html

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


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

Предыдущее
От: Michael Fuhr
Дата:
Сообщение: Re: getting back autonumber just inserted
Следующее
От: PFC
Дата:
Сообщение: Re: getting back autonumber just inserted