Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 6E03D2E00AD for ; Thu, 6 Mar 2008 11:29:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 17851-03 for ; Thu, 6 Mar 2008 11:28:46 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail.emolecules.com (66-226-76-106.dedicated.abac.net [66.226.76.106]) by postgresql.org (Postfix) with ESMTP id E49A22E2D76 for ; Thu, 6 Mar 2008 11:28:54 -0400 (AST) Received: (qmail 23242 invoked by uid 2020); 6 Mar 2008 07:28:52 -0800 Received: from wsip-68-224-174-233.sd.sd.cox.net (HELO lisa-james-computer.local) (68.224.174.233) by 192.168.0.4 with SMTP; 6 Mar 2008 07:28:52 -0800 Message-ID: <47D00DB2.7040007@emolecules.com> Date: Thu, 06 Mar 2008 07:28:50 -0800 From: Craig James User-Agent: Thunderbird 2.0.0.12 (Macintosh/20080213) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: count * performance issue References: <20080306060829.GA21084@a-kretschmer.de> <47CF8EA6.8070503@mark.mielke.cc> <20080306063643.GB21084@a-kretschmer.de> <3E9C3A51-C28E-4B75-9739-E344DAC72880@fastcrypt.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/122 X-Sequence-Number: 29076 In the 3 years I've been using Postgres, the problem of count() performance has come up more times than I can recall, and each time the answer is, "It's a sequential scan -- redesign your application." My question is: What do the other databases do that Postgres can't do, and why not? Count() on Oracle and MySQL is almost instantaneous, even for very large tables. So why can't Postgres do what they do? On the one hand, I understand that Postgres has its architecture, and I understand the issue of row visibility, and so forth. On the other hand, my database is just sitting there, nothing going on, no connections except me, and... it takes FIFTY FIVE SECONDS to count 20 million rows, a query that either Oracle or MySQL would answer in a fraction of a second. It's hard for me to believe there isn't a better way. This is a real problem. Countless people (including me) have spent significant effort rewriting applications because of this performance flaw in Postgres. Over and over, the response is, "You don't really need to do that ... change your application." Well, sure, it's always possible to change the application, but that misses the point. To most of us users, count() seems like it should be a trivial operation. On other relational database systems, it is a trivial operation. This is really a significant flaw on an otherwise excellent relational database system. My rant for today... Craig