Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 89053641690 for ; Thu, 10 Jun 2010 16:34:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 25205-08 for ; Thu, 10 Jun 2010 19:34:14 +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 97EAF641673 for ; Thu, 10 Jun 2010 16:34:14 -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 12:34:11 -0700 Message-ID: <4C113E2F.6000305@collab.net> Date: Thu, 10 Jun 2010 12:34:07 -0700 From: Anne Rosset User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Jochen Erwied CC: pgsql-performance@postgresql.org Subject: Re: Need to increase performance of a query References: <4C1125F0.8090101@collab.net> <4C112B19.6080908@krogh.cc> <4C113098.5040105@collab.net> <98414706.20100610212211@erwied.eu> In-Reply-To: <98414706.20100610212211@erwied.eu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 10 Jun 2010 19:34:11.0147 (UTC) FILETIME=[E6ADE9B0:01CB08D3] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-10 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/176 X-Sequence-Number: 39032 Jochen Erwied wrote: > Thursday, June 10, 2010, 8:36:08 PM you wrote: > > >> 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; >> > > Don't think it does really matter, but why do you sort a resultset > consisting of only one row? > > Sorry, I should have removed the ORDER by (the full query has a union). So without the ORDER by, here are the results: psrdb=# SELECT psrdb-# MAX(item_rank.rank) AS maxRank psrdb-# FROM psrdb-# item_rank item_rank psrdb-# WHERE psrdb-# item_rank.pf_id='plan1408'; maxrank ------------- 20504000000 (1 row) Time: 1.516 ms 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; maxrank ------------- 20200000000 (1 row) Time: 13.177 ms Is there anything that can be done for the second one? Thanks, Anne