Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 3B2CA2E008E for ; Tue, 3 Jun 2008 05:31:54 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 18222-05 for ; Tue, 3 Jun 2008 05:31:46 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from depesz.com (depesz.com [88.198.37.40]) by developer.postgresql.org (Postfix) with ESMTP id 3EC462E005B for ; Tue, 3 Jun 2008 05:31:49 -0300 (ADT) Received: from depesz by depesz.com with local (Exim 4.63) (envelope-from ) id 1K3Rvm-0004gN-Lc; Tue, 03 Jun 2008 10:31:46 +0200 Date: Tue, 3 Jun 2008 10:31:46 +0200 From: hubert depesz lubaczewski To: Marcin Citowicki Cc: pgsql-performance@postgresql.org Subject: Re: query performance question Message-ID: <20080603083146.GB17220@depesz.com> Reply-To: depesz@depesz.com References: <4844F95B.4040009@m4n.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4844F95B.4040009@m4n.nl> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/9 X-Sequence-Number: 30359 On Tue, Jun 03, 2008 at 09:57:15AM +0200, Marcin Citowicki wrote: > I'm not a dba so I'm not sure if the time it takes to execute this query > is OK or not, it just seems a bit long to me. This is perfectly OK. count(*) from table is generally slow. There are some ways to make it faster (depending if you need exact count, or some estimate). > I'd appreciate it if someone could share his/her thoughts on this. Is > there a way to make this table/query perform better? You can keep the count of elements in this table in separate table, and update it with triggers. > Any query I'm running that joins with transactions table takes forever > to complete, but maybe this is normal for a table this size. As for other queries - show them, and their explain analyze. Performance of count(*) is dependent basically only on size of table. In case of other queries - it might be simple to optimize them. Or impossible - without knowing the queries it's impossible to tell. Do you really care about count(*) from 60m+ record table? How often do you count the records? Best regards, depesz