Re: count * performance issue - Mailing list pgsql-performance

From Craig James
Subject Re: count * performance issue
Date
Msg-id 47D00DB2.7040007@emolecules.com
Whole thread Raw
In response to Re: count * performance issue  (Greg Smith <gsmith@gregsmith.com>)
Responses Re: count * performance issue  (Bruce Momjian <bruce@momjian.us>)
Re: count * performance issue  ("Steinar H. Gunderson" <sgunderson@bigfoot.com>)
Re: count * performance issue  (Bill Moran <wmoran@collaborativefusion.com>)
Re: count * performance issue  ("Mark Lewis" <mark.lewis@mir3.com>)
Re: count * performance issue  ("D'Arcy J.M. Cain" <darcy@druid.net>)
Re: count * performance issue  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: count * performance issue  (Mark Kirkwood <markir@paradise.net.nz>)
Re: count * performance issue  (Arjen van der Meijden <acmmailing@tweakers.net>)
List pgsql-performance
In the 3 years I've been using Postgres, the problem of count() performance has come up more times than I can recall,
andeach 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
takesFIFTY 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
ofthis 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

pgsql-performance by date:

Previous
From: Greg Smith
Date:
Subject: Re: postgresql Explain command output
Next
From: Bruce Momjian
Date:
Subject: Re: count * performance issue