Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id BB60E632712 for ; Tue, 10 Aug 2010 14:53:16 -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 33339-06 for ; Tue, 10 Aug 2010 17:53:09 +0000 (UTC) X-Greylist: delayed 00:15:00.494587 by SQLgrey-1.7.6 Received: from mxout12.netvision.net.il (mxout12.netvision.net.il [194.90.6.37]) by mail.postgresql.org (Postfix) with ESMTP id 10DEE632AFC for ; Tue, 10 Aug 2010 14:53:09 -0300 (ADT) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII Received: from jblaptop ([82.166.115.175]) by mxout12.netvision.net.il (Sun Java(tm) System Messaging Server 7u3-15.01 64bit (built Feb 12 2010)) with ESMTPA id <0L6Y00EEQ6BIYOB0@mxout12.netvision.net.il> for pgsql-performance@postgresql.org; Tue, 10 Aug 2010 20:38:06 +0300 (IDT) From: Jonathan Blitz To: pgsql-performance@postgresql.org References: <4C613A04020000250003441E@gw.wicourts.gov> Subject: Re: Sorted group by Date: Tue, 10 Aug 2010 20:38:02 +0300 Message-id: <80C83A54DDD9410F87FC9DDC78967ED0@jblaptop> X-Mailer: Microsoft Office Outlook 11 In-reply-to: <4C613A04020000250003441E@gw.wicourts.gov> X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.5931 Thread-index: Acs4qm8d1+L0lOOISw+dBZzwd/eSAgAB5Bcg X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201008/113 X-Sequence-Number: 39956 Another couple of possible ways: Select groupfield,value From tbl x1 Where number = (select max(number) from tbl x2 where x2.groupfield= x1.groupfield) Select groupfield,value From tbl x1 Where (groupfield,number) in (select groupfield,max(number) from tbl group by groupfield) Which is quickest? Probably best to try out and see. -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owner@postgresql.org] On Behalf Of Kevin Grittner Sent: Tuesday, August 10, 2010 7:38 PM To: Matthew Wakeling; pgsql-performance@postgresql.org Subject: Re: [PERFORM] Sorted group by Matthew Wakeling wrote: > I'm trying to eke a little bit more performance out of an application In addition to the suggestion from Thomas Kellerer, it would be interesting to try the following and see how performance compares using real data. select group, value from tbl x where not exists (select * from tbl y where y.group = x.group and y.number > x.number); We have a lot of code using this general technique, and I'm curious whether there are big gains to be had by moving to the windowing functions. (I suspect there are.) -Kevin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.851 / Virus Database: 271.1.1/3061 - Release Date: 08/09/10 21:35:00