From: | "Shoaib Mir" <shoaibmir(at)gmail(dot)com> |
---|---|
To: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: count * performance issue |
Date: | 2008-03-06 06:15:06 |
Message-ID: | bf54be870803052215y5bb56235k5ea05ada1d701022@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Thu, Mar 6, 2008 at 5:08 PM, A. Kretschmer <
andreas(dot)kretschmer(at)schollglas(dot)com> wrote:>
> > am having a table with nearly 50 lakh records,
> >
> > it has more than 15 columns, i want to count how many records are there,
> it is
> > taking nearly 17 seconds to do that...
> >
> > i know that to get a approximate count we can use
> > SELECT reltuples FROM pg_class where relname = TABLENAME;
> >
> > but this give approximate count, and i require exact count...
>
> There aren't a general solution. If you realy need the exact count of
> tuples than you can play with a TRIGGER and increase/decrease the
> tuple-count for this table in an extra table.
>
>
>
Or do something like:
ANALYZE tablename;
select reltuple from pg_class where relname = 'tablename';
That will also return the total number of rows in a table and I guess might
be much faster then doing a count(*) but yes if trigger can be an option
that can be the easiest way to do it and fastest too.
--
Shoaib Mir
Fujitsu Australia Software Technology
shoaibm[(at)]fast(dot)fujitsu(dot)com(dot)au
From | Date | Subject | |
---|---|---|---|
Next Message | sathiya psql | 2008-03-06 06:19:08 | Re: count * performance issue |
Previous Message | RaviRam Kolipaka | 2008-03-06 06:10:05 | postgresql Explain command output |