Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 56C77641B16 for ; Thu, 10 Jun 2010 16:45:04 -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 69772-02 for ; Thu, 10 Jun 2010 19:44:56 +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 E0234641BBA for ; Thu, 10 Jun 2010 16:44:56 -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:44:54 -0700 Message-ID: <4C1140B6.5020803@collab.net> Date: Thu, 10 Jun 2010 12:44:54 -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> <4C113E2F.6000305@collab.net> <10510424234.20100610213924@erwied.eu> In-Reply-To: <10510424234.20100610213924@erwied.eu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 10 Jun 2010 19:44:55.0287 (UTC) FILETIME=[669DE070:01CB08D5] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_20=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/181 X-Sequence-Number: 39037 Jochen Erwied wrote: > Thursday, June 10, 2010, 9:34:07 PM you wrote: > > >> Time: 1.516 ms >> > > >> Time: 13.177 ms >> > > I'd suppose the first query to scan a lot less rows than the second one. > Could you supply an explained plan for the fast query? > > Hi Jochen, Here is the explained plan for the fastest query: psrdb=# explain analyze ELECT psrdb-# MAX(item_rank.rank) AS maxRank psrdb-# FROM psrdb-# item_rank item_rank psrdb-# WHERE psrdb-# item_rank.pf_id='plan1408'; ERROR: syntax error at or near "ELECT" at character 17 psrdb=# explain analyze SELECT psrdb-# MAX(item_rank.rank) AS maxRank psrdb-# FROM psrdb-# item_rank item_rank psrdb-# WHERE psrdb-# item_rank.pf_id='plan1408'; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=8.28..8.29 rows=1 width=8) (actual time=0.708..0.709 rows=1 loops=1) -> Index Scan using item_rank_pf on item_rank (cost=0.00..8.27 rows=1 width=8) (actual time=0.052..0.407 rows=303 loops=1) Index Cond: ((pf_id)::text = 'plan1408'::text) Total runtime: 0.761 ms (4 rows) Time: 2.140 ms