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

From Craig James
Subject Re: count * performance issue
Date
Msg-id 47D0AFC1.5070305@emolecules.com
Whole thread Raw
In response to Re: count * performance issue  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: count * performance issue  (paul rivers <rivers.paul@gmail.com>)
Re: count * performance issue  (Mark Kirkwood <markir@paradise.net.nz>)
Benchmark: Dell/Perc 6, 8 disk RAID 10  (Craig James <craig_james@emolecules.com>)
List pgsql-performance
Tom Lane wrote:
> Craig James <craig_james@emolecules.com> writes:
>> Count() on Oracle and MySQL is almost instantaneous, even for very large tables. So why can't Postgres do what they
do?
>
> AFAIK the above claim is false for Oracle.  They have the same
> transactional issues we do.

My experience doesn't match this claim.  When I ported my application from Oracle to Postgres, this was the single
biggestperformance problem.  count() in Oracle was always very fast.  We're not talking about a 20% or 50% difference,
we'retalking about a small fraction of a second (Oracle) versus a minute (Postgres) -- something like two or three
ordersof magnitude. 

It may be that Oracle has a way to detect when there's no transaction and use a faster method.  If so, this was a
cleveroptimization -- in my experience, that represents the vast majority of the times you want to use count().  It's
notvery useful to count the rows of a table that many apps are actively modifying since the result may change the
momentyour transaction completes.  Most of the time when you use count(), it's because you're the only one modifying
thetable, so the count will be meaningful. 

Craig


pgsql-performance by date:

Previous
From: Mark Kirkwood
Date:
Subject: Re: count * performance issue
Next
From: "b wragg"
Date:
Subject: Improve Full text rank in a query