Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id C544C641B25 for ; Thu, 10 Jun 2010 16:42:33 -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 36191-07 for ; Thu, 10 Jun 2010 19:42:25 +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 2A72A641A3A for ; Thu, 10 Jun 2010 16:42:24 -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:42:22 -0700 Message-ID: <4C11401D.5000400@collab.net> Date: Thu, 10 Jun 2010 12:42:21 -0700 From: Anne Rosset User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Kenneth Marshall CC: Jochen Erwied , 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> <4C113E2F.6000305@collab.net> <20100610193712.GL3063@aart.is.rice.edu> In-Reply-To: <20100610193712.GL3063@aart.is.rice.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 10 Jun 2010 19:42:22.0603 (UTC) FILETIME=[0B9C25B0:01CB08D5] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/180 X-Sequence-Number: 39036 Kenneth Marshall wrote: > On Thu, Jun 10, 2010 at 12:34:07PM -0700, Anne Rosset wrote: > >> 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 >> >> > What about an IS NULL index on pf_id? > > Regards, > Ken > Hi Ken, I have the following index: "item_rank_index2" btree (project_id) WHERE (pf_id IS NULL) Are you suggesting something else? Thanks, Anne