From: Jaime Casanova <systemguards@gmail.com>
To: Rodrigo Madera <rodrigo.madera@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Newbie question: ultra fast count(*)
Date: Fri, 25 Nov 2005 14:40:06 -0500
Message-ID: <c2d9e70e0511251140x5f2a6c2ah6fc81d88fcfb2213@mail.gmail.com> (raw)
In-Reply-To: <3cf983d0511251136j1afa0ec4i9a3987d250befe47@mail.gmail.com>
References: <3cf983d0511251136j1afa0ec4i9a3987d250befe47@mail.gmail.com>
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 ;)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: systemguards@gmail.com, rodrigo.madera@gmail.com
Subject: Re: Newbie question: ultra fast count(*)
In-Reply-To: <c2d9e70e0511251140x5f2a6c2ah6fc81d88fcfb2213@mail.gmail.com>
References: <3cf983d0511251136j1afa0ec4i9a3987d250befe47@mail.gmail.com> <c2d9e70e0511251140x5f2a6c2ah6fc81d88fcfb2213@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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