Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id ABFD663FD17 for ; Thu, 10 Jun 2010 15:36:20 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 86833-05 for ; Thu, 10 Jun 2010 18:36:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sp-exchfea.sp.corp.collab.net (sp-exchfea.sp.corp.collab.net [204.16.106.198]) by mail.postgresql.org (Postfix) with ESMTP id 5308D63FD11 for ; Thu, 10 Jun 2010 15:36:13 -0300 (ADT) Received: from [204.11.125.143] ([204.11.125.143]) by sp-exchfea.sp.corp.collab.net with Microsoft SMTPSVC(6.0.3790.3959); Thu, 10 Jun 2010 11:36:11 -0700 Message-ID: <4C113098.5040105@collab.net> Date: Thu, 10 Jun 2010 11:36:08 -0700 From: Anne Rosset User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Jesper Krogh CC: pgsql-performance@postgresql.org Subject: Re: Need to increase performance of a query References: <4C1125F0.8090101@collab.net> <4C112B19.6080908@krogh.cc> In-Reply-To: <4C112B19.6080908@krogh.cc> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 10 Jun 2010 18:36:11.0643 (UTC) FILETIME=[CCBBBCB0:01CB08CB] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/175 X-Sequence-Number: 39031 Jesper Krogh wrote: > On 2010-06-10 19:50, Anne Rosset wrote: >> Any advice on how to make it run faster? > > What timing do you get if you run it with \t (timing on) and without > explain analyze ? > > I would be surprised if you can get it much faster than what is is.. I > may be that a > significant portion is "planning cost" so if you run it a lot you > might benefit from > a prepared statement. > > Hi Jesper, Thanks your response: psrdb=# \timing Timing is on. psrdb=# (SELECT psrdb(# MAX(item_rank.rank) AS maxRank psrdb(# FROM psrdb(# item_rank item_rank psrdb(# WHERE psrdb(# item_rank.project_id='proj2783' psrdb(# AND item_rank.pf_id IS NULL psrdb(# psrdb(# ) psrdb-# ORDER BY psrdb-# maxRank DESC; maxrank ------------- 20200000000 (1 row) Time: 12.947 ms It really seems to me that it should take less time. Specially when I see the result with a different where clause like this one: psrdb=# SELECT psrdb-# MAX(item_rank.rank) AS maxRank psrdb-# FROM psrdb-# item_rank item_rank psrdb-# WHERE psrdb-# item_rank.pf_id='plan1408' psrdb-# ORDER BY psrdb-# maxRank DESC; maxrank ------------- 20504000000 (1 row) Time: 2.582 ms Thanks, Anne