Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id F318C9FB409 for ; Fri, 1 Jun 2007 14:04:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 37837-01-9 for ; Fri, 1 Jun 2007 14:03:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mtao01.charter.net (mtao01.charter.net [209.225.8.186]) by postgresql.org (Postfix) with ESMTP id 676C59FC27D for ; Fri, 1 Jun 2007 14:03:39 -0300 (ADT) Received: from aa02.charter.net ([10.20.200.154]) by mtao01.charter.net (InterMail vM.7.08.02.00 201-2186-121-20061213) with ESMTP id <20070601170334.PATR1477.mtao01.charter.net@aa02.charter.net>; Fri, 1 Jun 2007 13:03:34 -0400 Received: from [10.0.1.3] (really [66.188.164.45]) by aa02.charter.net with ESMTP id <20070601170334.BTCR22936.aa02.charter.net@[10.0.1.3]>; Fri, 1 Jun 2007 13:03:34 -0400 In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <96F60F91-F3A7-4134-8DD0-E519C8941CDB@seespotcode.net> Cc: pgsql-performance@postgresql.org Content-Transfer-Encoding: 7bit From: Michael Glaesemann Subject: Re: Seq Scan Date: Fri, 1 Jun 2007 12:03:30 -0500 To: Tyler Durden X-Mailer: Apple Mail (2.752.2) X-Chzlrs: 0 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/3 X-Sequence-Number: 25036 On Jun 1, 2007, at 11:48 , Tyler Durden wrote: > I'm having some problems in performance in a simple select count(id) > from.... Unrestricted count() (i.e., no WHERE clause) will perform a sequential scan. If you're looking for faster ways to store table row count information, please search the archives, as this has been discussed many times before. > # explain select (id) from table_name; > -[ RECORD > 1 ]---------------------------------------------------------------- > QUERY PLAN | Seq Scan on table_name (cost=0.00..8601.30 > rows=266730 width=4) The query returns the id column value for each row in the table. The fastest way to do this is visiting every row., i.e., a sequential scan. Using an index would require (1) looking in the index and (2) looking up the corresponding row. Michael Glaesemann grzm seespotcode net