Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 5C6712E00A7 for ; Tue, 3 Jun 2008 05:58:45 -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 48503-01 for ; Tue, 3 Jun 2008 05:58:26 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mrxmail0.mbuyu.com (mrxmail0.mbuyu.com [85.158.204.176]) by developer.postgresql.org (Postfix) with ESMTP id ED4D92E009E for ; Tue, 3 Jun 2008 05:58:24 -0300 (ADT) Received: from [172.16.26.14] (a82-93-9-158.adsl.xs4all.nl [82.93.9.158]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mrxmail0.mbuyu.com (Postfix) with ESMTP id 946A22659E; Tue, 3 Jun 2008 10:58:21 +0200 (CEST) Message-ID: <484506FA.9000706@m4n.nl> Date: Tue, 03 Jun 2008 10:55:22 +0200 From: Marcin Citowicki User-Agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080110) MIME-Version: 1.0 To: depesz@depesz.com CC: pgsql-performance@postgresql.org Subject: Re: query performance question References: <4844F95B.4040009@m4n.nl> <20080603083146.GB17220@depesz.com> In-Reply-To: <20080603083146.GB17220@depesz.com> Content-Type: multipart/mixed; boundary="------------040300010708050400070105" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL=-0.001, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200806/10 X-Sequence-Number: 30360 This is a multi-part message in MIME format. --------------040300010708050400070105 Content-Type: multipart/alternative; boundary="------------000008070709000105030804" --------------000008070709000105030804 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hello Hubert, Thank you for your reply. I don't really need to count rows in transactions table, I just thought this was a good example to show how slow the query was. But based on what you wrote it looks like count(*) is slow in general, so this seems to be OK since the table is rather large. I just ran other queries (joining transactions table) and they returned quickly, which leads me to believe that there could be a problem not with the database, but with the box the db is running on. Sometimes those same queries take forever and now they complete in no time at all, so perhaps there is a process that is running periodically which is slowing the db down. I'll need to take a look at this. Thank you for your help! Marcin hubert depesz lubaczewski wrote: > 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 > > --------------000008070709000105030804 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit Hello Hubert,

Thank you for your reply. I don't really need to count rows in transactions table, I just thought this was a good example to show how slow the query was.
But based on what you wrote it looks like count(*) is slow in general, so this seems to be OK since the table is rather large.
I just ran other queries (joining transactions table) and they returned quickly, which leads me to believe that there could be a problem not with the database, but with the box
the db is running on. Sometimes those same queries take forever and now they complete in no time at all, so perhaps there is a process that is running periodically which is slowing the db down.
I'll need to take a look at this.
Thank you for your help!

Marcin


hubert depesz lubaczewski wrote:
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

  
--------------000008070709000105030804-- --------------040300010708050400070105 Content-Type: text/x-vcard; charset=utf-8; name="marcin_citowicki.vcf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="marcin_citowicki.vcf" YmVnaW46dmNhcmQNCmZuOk1hcmNpbiBDaXRvd2lja2kNCm46Q2l0b3dpY2tpO01hcmNpbg0K ZW1haWw7aW50ZXJuZXQ6bWFyY2luLmNpdG93aWNraUBtNG4ubmwNCngtbW96aWxsYS1odG1s OkZBTFNFDQp2ZXJzaW9uOjIuMQ0KZW5kOnZjYXJkDQoNCg== --------------040300010708050400070105--