X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 33CFF9DCA16 for ; Thu, 23 Feb 2006 18:47:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 85722-07 for ; Thu, 23 Feb 2006 18:47:28 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id F1CC39DC81D for ; Thu, 23 Feb 2006 18:47:24 -0400 (AST) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:35149 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1FCPF9-0005ol-HO for pgsql-sql@postgresql.org; Thu, 23 Feb 2006 17:47:27 -0500 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 2EC614051; Thu, 23 Feb 2006 17:47:23 -0500 (EST) Date: Thu, 23 Feb 2006 17:47:23 -0500 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: Question about index scan vs seq scan when using count() Message-ID: <20060223224723.GG11392@phlogiston.dyndns.org> References: <18AE59788A3FC640A367E5652E664D800199BEE8@xmb-sjc-237.amer.cisco.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18AE59788A3FC640A367E5652E664D800199BEE8@xmb-sjc-237.amer.cisco.com> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.086 required=5 tests=[AWL=0.086] X-Spam-Score: 0.086 X-Spam-Level: X-Archive-Number: 200602/289 X-Sequence-Number: 24299 On Thu, Feb 23, 2006 at 02:25:34PM -0800, Kashmira Patel (kupatel) wrote: > > [Kashmira] I did do an EXPLAIN ANALYZE as well, it also showed a > sequential scan. The table has about 600+ rows, with around 6 of them > matching the given id. Wouldn't an index scan be faster in this case? EXPLAIN ANALYSE will always choose the same plan as EXPLAIN. The difference is that it shows you the estimate and actual. I am surprised you're getting a seqscan for that, though. Is there something about the index you're not telling us? Is your system tuned correctly? Maybe 600 rows is so small that a seqscan's just as fast. A -- Andrew Sullivan | ajs@crankycanuck.ca "The year's penultimate month" is not in truth a good way of saying November. --H.W. Fowler