pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: sathiya psql <sathiya.psql@gmail.com>
To: Shoaib Mir <shoaibmir@gmail.com>
Cc: A. Kretschmer <andreas.kretschmer@schollglas.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: count * performance issue
Date: Thu, 6 Mar 2008 11:49:08 +0530
Message-ID: <f966c2ee0803052219x393929c4w321f65e659f1617b@mail.gmail.com> (raw)
In-Reply-To: <bf54be870803052215y5bb56235k5ea05ada1d701022@mail.gmail.com>
References: <f966c2ee0803052142l6a105678jfe2da92a0d9371@mail.gmail.com>
	<f966c2ee0803052143k4570d771o6c300647d3b987d@mail.gmail.com>
	<20080306060829.GA21084@a-kretschmer.de>
	<bf54be870803052215y5bb56235k5ea05ada1d701022@mail.gmail.com>

buy every time i need to put ANALYZE...
this takes the same time as count(*) takes, what is the use ??

On Thu, Mar 6, 2008 at 11:45 AM, Shoaib Mir <shoaibmir@gmail.com> wrote:

> On Thu, Mar 6, 2008 at 5:08 PM, A. Kretschmer <
> andreas.kretschmer@schollglas.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[@]fast.fujitsu.com.au

view thread (62+ messages)  latest in thread

Message-ID: <f966c2ee0803052219x393929c4w321f65e659f1617b@mail.gmail.com>
Permalink:  ../f966c2ee0803052219x393929c4w321f65e659f1617b@mail.gmail.com/
Also on:    postgresql.org/message-id/f966c2ee0803052219x393929c4w321f65e659f1617b@mail.gmail.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: sathiya.psql@gmail.com, shoaibmir@gmail.com, andreas.kretschmer@schollglas.com
  Subject: Re: count * performance issue
  In-Reply-To: <f966c2ee0803052219x393929c4w321f65e659f1617b@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