Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 836212E027E for ; Thu, 6 Mar 2008 02:08:36 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 00906-07 for ; Thu, 6 Mar 2008 02:08:33 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by postgresql.org (Postfix) with ESMTP id B482A2E026C for ; Thu, 6 Mar 2008 02:08:32 -0400 (AST) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mrelayeu2) with ESMTP (Nemesis) id 0MKwtQ-1JX9HK2hHL-000436; Thu, 06 Mar 2008 07:08:31 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1JX9HJ-0005av-00 for pgsql-performance@postgresql.org; Thu, 06 Mar 2008 07:08:29 +0100 Date: Thu, 6 Mar 2008 07:08:29 +0100 From: "A. Kretschmer" To: pgsql-performance@postgresql.org Subject: Re: count * performance issue Message-ID: <20080306060829.GA21084@a-kretschmer.de> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX1++sidsWJH4yUzNZHXY00RI6N+6MuzOXnx0Sgl BfhitLq8PFd/Wcjx6vj0U0hzI4Q89VqI7W5fFjqY0VMgBTRYVI yltnp3LYksjAtGuy7gR0V+0WiYn1xNo X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/90 X-Sequence-Number: 29044 am Thu, dem 06.03.2008, um 11:13:01 +0530 mailte sathiya psql folgendes: > count(*) tooks much time... > > but with the where clause we can make this to use indexing,... what where > clause we can use?? An index without a WHERE can't help to avoid a seq. scan. > > Am using postgres 7.4 in Debian OS with 1 GB RAM, PG 7.4 are very old... Recent versions are MUCH faster. > > 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. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net