Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 288A49F9288 for ; Wed, 5 Sep 2007 09:48:24 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 20753-05 for ; Wed, 5 Sep 2007 09:48:20 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.235]) by postgresql.org (Postfix) with ESMTP id 9F75B9F9A6F for ; Wed, 5 Sep 2007 09:48:20 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id 68so993364wri for ; Wed, 05 Sep 2007 05:48:19 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=JLsHouhDYyuIe8oupXrO0o9/BUGYPD1vqMrwYKso+gpENYIsVRUyKmTgCbCcXxdVukqR6YN3Iri9F1A1vnvUFYPP3RoEf6wSZtbUy5OGMK/qSOW8GecFhzHEQX/kBuPdc+uLxwpZ1+dPso07mb4cUB+ZbPKqCNeHyE6/bLsE+o0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=TkwbpXk8Gj5QFiowtr9fUGTanr8v87caNCFmBFAPTlHd/B7FfTDCr+uXctZmndFxClxGoz5LXmFlk4fcjBaa20JCJ2KRJcBtpUN4IUiF1KZtIN/PDgpkwXwHFlopOxr6mE8ER1WCcxkpcghs4w/xWOwbrlWkPPRhsaE5a0XYz+0= Received: by 10.90.95.11 with SMTP id s11mr6913935agb.1188996498743; Wed, 05 Sep 2007 05:48:18 -0700 (PDT) Received: by 10.90.34.18 with HTTP; Wed, 5 Sep 2007 05:48:18 -0700 (PDT) Message-ID: <162867790709050548l3e1fd155g40b745f2ae42834e@mail.gmail.com> Date: Wed, 5 Sep 2007 14:48:18 +0200 From: "Pavel Stehule" To: "Peter Childs" Subject: Re: optimize query with a maximum(date) extraction Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <302443.65402.qm@web26209.mail.ukl.yahoo.com> <87abs1qrhu.fsf@oxford.xeocode.com> <87642pqpue.fsf@oxford.xeocode.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/42 X-Sequence-Number: 26587 > > why not > > select id, > min(the_date) as min_date, > max(the_date) as max_date > from my_table group by id; > > Since 8.0 or was it earlier this will use an index should a reasonable one > exist. without any limits, seq scan is optimal. Regards Pavel Stehule