Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id B5A329F9BDE for ; Wed, 5 Sep 2007 12:23:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 07336-05 for ; Wed, 5 Sep 2007 12:23:44 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id E4E819F936E for ; Wed, 5 Sep 2007 12:23:43 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l85FNcpx013390; Wed, 5 Sep 2007 11:23:38 -0400 (EDT) To: Gregory Stark cc: "Pavel Stehule" , "Peter Childs" , pgsql-performance@postgresql.org Subject: Re: optimize query with a maximum(date) extraction In-reply-to: <87ps0xp4nu.fsf@oxford.xeocode.com> References: <302443.65402.qm@web26209.mail.ukl.yahoo.com> <87abs1qrhu.fsf@oxford.xeocode.com> <87642pqpue.fsf@oxford.xeocode.com> <162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.com> <87ps0xp4nu.fsf@oxford.xeocode.com> Comments: In-reply-to Gregory Stark message dated "Wed, 05 Sep 2007 15:28:53 +0100" Date: Wed, 05 Sep 2007 11:23:38 -0400 Message-ID: <13389.1189005818@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/51 X-Sequence-Number: 26596 Gregory Stark writes: > You can simulate such a plan with the subqueries I described but > there's a bit more overhead than necessary and you need a reasonably > efficient source of the distinct ids. Yeah, that seems like the $64 question. If you have no better way of finding out the set of ID values than a seqscan, then there's no point in trying to optimize the min/max accumulation ... regards, tom lane