Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id BD3A22E034D for ; Fri, 7 Mar 2008 21:24:06 -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 84824-08 for ; Fri, 7 Mar 2008 21:23:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from davinci.ethosmedia.com (unknown [209.128.84.227]) by postgresql.org (Postfix) with ESMTP id 9C82E2E01DC for ; Fri, 7 Mar 2008 21:24:02 -0400 (AST) X-EthosMedia-Virus-Scanned: no infections found Received: from [64.81.245.111] (account josh@agliodbs.com HELO temoku.sf.agliodbs.com) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 15751508; Fri, 07 Mar 2008 17:29:01 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: pgsql-performance@postgresql.org Subject: Re: count * performance issue Date: Fri, 7 Mar 2008 17:27:35 -0800 User-Agent: KMail/1.8 Cc: Tom Lane , Craig James References: <47D00DB2.7040007@emolecules.com> <18451.1204824562@sss.pgh.pa.us> In-Reply-To: <18451.1204824562@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200803071727.36146.josh@agliodbs.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/171 X-Sequence-Number: 29125 Tom, > > 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. Nope. Oracle's MVCC is implemented through rollback segments, rather than non-overwriting the way ours is. So Oracle can just do a count(*) on the index, then check the rollback segment for any concurrent update/delete/insert activity and adjust the count. This sucks if there's a *lot* of concurrent activity, but in the usual case it's pretty fast. I've been thinking that when we apply the Dead Space Map we might be able to get a similar effect in PostgreSQL. That is, just do a count over the index, and visit only the heap pages flagged in the DSM. Again, for a heavily updated table this wouldn't have any benefit, but for most cases it would be much faster. -- --Josh Josh Berkus PostgreSQL @ Sun San Francisco