pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Newbie question: ultra fast count(*)
3+ messages / 3 participants
[nested] [flat]

* Newbie question: ultra fast count(*)
@ 2005-11-25 19:36  Rodrigo Madera <rodrigo.madera@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Rodrigo Madera @ 2005-11-25 19:36 UTC (permalink / raw)
  To: pgsql-performance

I have been reading all this technical talk about costs and such that
I don't (_yet_) understand.

Now I'm scared... what's the fastest way to do an equivalent of
count(*) on a table to know how many items it has?

Thanks,
Rodrigo



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Newbie question: ultra fast count(*)
@ 2005-11-25 19:40  Jaime Casanova <systemguards@gmail.com>
  parent: Rodrigo Madera <rodrigo.madera@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Jaime Casanova @ 2005-11-25 19:40 UTC (permalink / raw)
  To: Rodrigo Madera <rodrigo.madera@gmail.com>; +Cc: pgsql-performance

On 11/25/05, Rodrigo Madera <rodrigo.madera@gmail.com> wrote:
> I have been reading all this technical talk about costs and such that
> I don't (_yet_) understand.
>
> Now I'm scared... what's the fastest way to do an equivalent of
> count(*) on a table to know how many items it has?
>
> Thanks,
> Rodrigo
>

you really *need* this?

you can do
SELECT reltuples FROM pg_class WHERE relname = 'your_table_name';

but this will give you an estimate... if you want real values you can
make a TRIGGER that maintain a counter in another table

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Newbie question: ultra fast count(*)
@ 2005-11-28 13:31  Merlin Moncure <merlin.moncure@rcsonline.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Merlin Moncure @ 2005-11-28 13:31 UTC (permalink / raw)
  To: Rodrigo Madera <rodrigo.madera@gmail.com>; +Cc: pgsql-performance

> I have been reading all this technical talk about costs and such that
> I don't (_yet_) understand.
> 
> Now I'm scared... what's the fastest way to do an equivalent of
> count(*) on a table to know how many items it has?

Make sure to analyze the database frequently and check pg_class for
reltuples field.  This gives 0 time approximations of # row in table at
the time of the last analyze.

Many other approaches...check archives.  Also your requirements are
probably not as high as you think they are ;)

Merlin




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-11-28 13:31 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-25 19:36 Newbie question: ultra fast count(*) Rodrigo Madera <rodrigo.madera@gmail.com>
2005-11-25 19:40 ` Jaime Casanova <systemguards@gmail.com>
2005-11-28 13:31 Re: Newbie question: ultra fast count(*) Merlin Moncure <merlin.moncure@rcsonline.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox