Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id EBB4E9FB682 for ; Sat, 23 Jun 2007 07:36:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 95984-01 for ; Sat, 23 Jun 2007 07:36:20 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from 137086.vserver.de (vs137086.vserver.de [62.75.137.86]) by postgresql.org (Postfix) with ESMTP id 5148E9FB5A6 for ; Sat, 23 Jun 2007 07:36:29 -0300 (ADT) Received: from a-kretschmer.de (p54B3B667.dip0.t-ipconnect.de [84.179.182.103]) (authenticated bits=0) by 137086.vserver.de (8.12.8/8.12.8) with ESMTP id l5NAaPM5022086 for ; Sat, 23 Jun 2007 12:36:26 +0200 Received: from kretschmer by a-kretschmer.de with local (Exim 4.61) (envelope-from ) id 1I2316-00078x-DT for pgsql-sql@postgresql.org; Sat, 23 Jun 2007 12:38:56 +0200 Date: Sat, 23 Jun 2007 12:38:56 +0200 From: Andreas Kretschmer To: pgsql-sql@postgresql.org Subject: Re: Counting all rows Message-ID: <20070623103856.GE7307@KanotixBox> References: Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-GPG-Fingerprint: EE16 3C01 7B9C 10F7 2C8B 3B86 4DB3 D9EE 7F45 84DA X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! X-Lugdd: Gerd Kube X-Info: My name is root. Just root. And I am licensed to kill -9 User-Agent: mutt-ng 1.5.9i (Linux) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.18 tagged_above=0 required=5 tests=AWL=0.044, BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200706/184 X-Sequence-Number: 28674 Stefan Arentz schrieb: > I need to get statistics from a bunch of tables. Simply the number of > records in them. > > The query plan looks like this: > > => explain select count(id) from stuff; > QUERY PLAN > ------------------------------------------------------------------- > Aggregate (cost=1629.69..1629.70 rows=1 width=8) > -> Seq Scan on stuff (cost=0.00..1517.75 rows=44775 width=8) > > The sequential scan kind of worries me. Is there a better/faster way to do > this? Yes. A "select count(*) from foo;" enforces a seq. scan. Solutions for this are discussed here: http://www.varlena.com/GeneralBits/120.php Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknow) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°