Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id B6495B5DBFC for ; Mon, 20 Jun 2011 12:41:27 -0300 (ADT) 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 79394-06 for ; Mon, 20 Jun 2011 15:41:21 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 5E825B5DBFA for ; Mon, 20 Jun 2011 12:41:21 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Mon, 20 Jun 2011 10:41:20 -0500 Message-Id: <4DFF23CC020000250003E994@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Mon, 20 Jun 2011 10:41:16 -0500 From: "Kevin Grittner" To: "Vladimir Kulev" , Subject: Re: Inoptimal query plan for max() and multicolumn index References: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/178 X-Sequence-Number: 44111 Vladimir Kulev wrote: > # explain analyze select max(timestamp) from sms where number in > ('5502712','5802693','5801981'); > According to planner cost estimations - it has enough data to > understand that it is better to aggregate maximum from three > subqueries. I suppose it's not a bug but not implemented feature Yeah, you're hoping for an optimization which hasn't been implemented. I expect you're hoping for a plan similar to what this gives you?: explain analyze select greatest( (select max(timestamp) from sms where number = '5502712'), (select max(timestamp) from sms where number = '5802693'), (select max(timestamp) from sms where number = '5801981')); -Kevin