Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 6C1F663257B for ; Wed, 24 Feb 2010 19:12:49 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 38474-08 for ; Wed, 24 Feb 2010 23:12:32 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay.ptn-ipout01.plus.net (relay.ptn-ipout01.plus.net [212.159.7.35]) by mail.postgresql.org (Postfix) with ESMTP id 055B5632387 for ; Wed, 24 Feb 2010 19:12:27 -0400 (AST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAEtBhUvUnw4R/2dsb2JhbACbE3O8GYRyBA Received: from pih-relay04.plus.net ([212.159.14.17]) by relay.ptn-ipout01.plus.net with ESMTP; 24 Feb 2010 23:12:26 +0000 Received: from [84.51.143.99] (helo=server3.office.archonet.com) by pih-relay04.plus.net with esmtp (Exim) id 1NkQP4-0007gQ-BK; Wed, 24 Feb 2010 23:12:26 +0000 Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTPA id DE3BC274044; Wed, 24 Feb 2010 23:12:25 +0000 (GMT) Message-ID: <4B85B259.4030900@archonet.com> Date: Wed, 24 Feb 2010 23:12:25 +0000 From: Richard Huxton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9pre) Gecko/20100213 Lightning/1.0b1 Shredder/3.0.2pre MIME-Version: 1.0 To: Dave Crooke CC: Garrett Murphy , pgsql-performance Subject: Re: Extracting superlatives - SQL design philosophy References: <076DC33A3D38CE4BBC64D35DDD9DE70C0A17259D@mse4be2.mse4.exchange.ms> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Plusnet-Relay: 5c78758c52f590cb6e83319d66008e30 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.49 tagged_above=-10 required=5 tests=AWL=-0.380, BAYES_05=-1.11 X-Spam-Level: X-Archive-Number: 201002/351 X-Sequence-Number: 37772 On 24/02/10 22:47, Dave Crooke wrote: > I'd imagine it would be possible to have a query planner optimization > that would convert Garrett's DISTINCT ON syntax to do what I was > trying to, by realizing that DISTINCT ON X ... ORDER BY Y DESC is > going to return the the one row for each X which has the highest value > of Y, and so use a MAX-structured accumulation instead of a sort. Why is there only one row? For city temperatures, that seems unlikely. In the event of more than one row does your algorithm give repeatable results? -- Richard Huxton Archonet Ltd