Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id AE2861337B61 for ; Thu, 24 Feb 2011 21:52:37 -0400 (AST) 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 14587-01 for ; Fri, 25 Feb 2011 01:52:30 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail149061.authsmtp.co.uk (outmail149061.authsmtp.co.uk [62.13.149.61]) by mail.postgresql.org (Postfix) with ESMTP id CA50D1337B4F for ; Thu, 24 Feb 2011 21:52:29 -0400 (AST) Received: from mail-c193.authsmtp.com (mail-c193.authsmtp.com [62.13.128.118]) by punt9.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id p1P1qOpH052946; Fri, 25 Feb 2011 01:52:24 GMT Received: from Sidney-Stratton.local (70-36-197-225.dsl.dynamic.sonic.net [70.36.197.225]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2) with ESMTP id p1P1qJsB013415; Fri, 25 Feb 2011 01:52:20 GMT Message-ID: <4D670B53.70003@agliodbs.com> Date: Thu, 24 Feb 2011 17:52:19 -0800 From: Josh Berkus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20090223 Thunderbird/3.0b2 MIME-Version: 1.0 To: Shaun Thomas CC: Dave Crooke , Kevin Grittner , Michael Glaesemann , pgsql-performance@postgresql.org Subject: Re: Picking out the most recent row using a time stamp column References: <08B3368E-E623-4E9C-83F5-AB05B471AF4C@seespotcode.net> <4D666A0F020000250003AFCE@gw.wicourts.gov> <4D66F5B0.5080502@agliodbs.com> <4D66FEB9.6000501@peak6.com> In-Reply-To: <4D66FEB9.6000501@peak6.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Server-Quench: e25dfe2f-4081-11e0-97bb-002264978518 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdyZgscClZXSx8a IioLCC5HRQ8+YBZL BAkGMA9GIUINWEQM c1AAcx19PVdbHwkA AnYLWl5RUldzWC1y axRSaxtca01QXQdv T0pMQFdNFEsoAHwA R2RdIBlzdAFHfTB4 YUdnECVZWRAsIEQr X0pUHWwbZGY1aH0W VxIKagNUcgFMehZC YlV+XD1vNG8XDRoV JSEUBRUEdQ1eIydU RA5FKk8OCVoLE3Y5 QAseVS8iFkADW20p KANuN0UdGklZOw0u MF4sEUkEOhoKaEVV GEVQBSkx X-Authentic-SMTP: 61633136333939.1014:706 X-AuthFastPath: 0 (Was 255) X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.6 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7 X-Spam-Level: X-Archive-Number: 201102/490 X-Sequence-Number: 42628 > Why did you use row_number instead of rank? Because I assumed he only wanted one row in the event of ties. Hmmm, although with that schema, there won't be ties. So it's pretty much arbitrary then. > I am now curious how the speed compares though. I still think the > DISTINCT ON will be faster, but it would be a great surprise. Hopefully we'll find out! The windowing functions are usually much faster for me. I think in 9.0 or 9.1 someone replumbed DISTINCT ON to use a bunch of the window function internals, at which point it'll cease to matter. -- -- Josh Berkus PostgreSQL Experts Inc. http://www.pgexperts.com