Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 24AF2641810 for ; Thu, 10 Jun 2010 16:37:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 26862-05 for ; Thu, 10 Jun 2010 19:37:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh3.mail.rice.edu (mh3.mail.rice.edu [128.42.199.10]) by mail.postgresql.org (Postfix) with ESMTP id 049D764180C for ; Thu, 10 Jun 2010 16:37:18 -0300 (ADT) Received: from mh3.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh3.mail.rice.edu (Postfix) with ESMTP id 31A16324033; Thu, 10 Jun 2010 14:37:15 -0500 (CDT) X-Virus-Scanned: by amavis-2.6.0 at mh3.mail.rice.edu Received: from mh3.mail.rice.edu ([127.0.0.1]) by mh3.mail.rice.edu (mh3.mail.rice.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YRC+OleyrWQR; Thu, 10 Jun 2010 14:37:14 -0500 (CDT) Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh3.mail.rice.edu (Postfix) with ESMTP id CEB49324069; Thu, 10 Jun 2010 14:37:12 -0500 (CDT) Received: by aart.is.rice.edu (Postfix, from userid 18612) id A151B2D5A6; Thu, 10 Jun 2010 14:37:12 -0500 (CDT) Date: Thu, 10 Jun 2010 14:37:12 -0500 From: Kenneth Marshall To: Anne Rosset Cc: Jochen Erwied , pgsql-performance@postgresql.org Subject: Re: Need to increase performance of a query Message-ID: <20100610193712.GL3063@aart.is.rice.edu> References: <4C1125F0.8090101@collab.net> <4C112B19.6080908@krogh.cc> <4C113098.5040105@collab.net> <98414706.20100610212211@erwied.eu> <4C113E2F.6000305@collab.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4C113E2F.6000305@collab.net> User-Agent: Mutt/1.5.16 (2007-06-09) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/177 X-Sequence-Number: 39033 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