Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id AE192B5DC1A for ; Fri, 15 Jul 2011 04:43:11 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 05166-01 for ; Fri, 15 Jul 2011 07:43:05 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id A337BB5DC17 for ; Fri, 15 Jul 2011 04:43:05 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id p6F7h52i007180 for ; Fri, 15 Jul 2011 04:43:05 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id p6F7Ehe2047985 for pgsql-performance@postgresql.org; Fri, 15 Jul 2011 04:14:43 -0300 (ADT) (envelope-from news) From: Gaetano Mendola X-Newsgroups: pgsql.performance Subject: Re: Inoptimal query plan for max() and multicolumn index Date: Fri, 15 Jul 2011 09:14:45 +0200 Organization: Hub.Org Networking Services Lines: 16 Message-ID: <4E1FE8E5.5000408@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org To: Vladimir Kulev User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 In-Reply-To: X-Antivirus: avast! (VPS 110714-1, 14/07/2011), Outbound message X-Antivirus-Status: Clean To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.813 tagged_above=-10 required=5 tests=BAYES_50=0.8, DOS_RCVD_IP_TWICE_B=0.001, FREEMAIL_FROM=0.001, RP_MATCHES_RCVD=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201107/154 X-Sequence-Number: 44366 On 20/06/2011 07:35, Vladimir Kulev wrote: > But this does not work: > # explain analyze select max(timestamp) from sms where number in > ('5502712','5802693','5801981'); Try to rewrite that query this way: explain analyze select timestamp from sms where number in ('5502712','5802693','5801981') order by timestamp desc limit 1; Regards Gaetano Mendola