Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 913779FB24C for ; Tue, 3 Oct 2006 16:15:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 80228-07 for ; Tue, 3 Oct 2006 19:15:26 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.refractions.net (mail.refractions.net [24.68.236.214]) by postgresql.org (Postfix) with ESMTP id C90F09FB30E for ; Tue, 3 Oct 2006 16:15:25 -0300 (ADT) Received: from lion.animals (lion [192.168.50.200]) by mail.refractions.net (Postfix) with ESMTP id 2258D122C369; Tue, 3 Oct 2006 12:23:36 -0700 (PDT) Received: by lion.animals (Postfix, from userid 88) id D1D42E3C3; Tue, 3 Oct 2006 12:15:24 -0700 (PDT) Received: from refractions.net (unknown [192.168.50.43]) by lion.animals (Postfix) with ESMTP id 41C39E3BD; Tue, 3 Oct 2006 12:15:23 -0700 (PDT) Message-ID: <4522B667.3060002@refractions.net> Date: Tue, 03 Oct 2006 12:13:43 -0700 From: Graham Davis Reply-To: gdavis@refractions.net User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Chris Browne Cc: pgsql-performance@postgresql.org Subject: Re: BUG #2658: Query not using index References: <200609272056.k8RKuWjY040283@wwwmaster.postgresql.org> <20061003000147.GA31475@wolff.to> <4522AA01.4020709@refractions.net> <60irj1gr3r.fsf@dba2.int.libertyrms.com> In-Reply-To: <60irj1gr3r.fsf@dba2.int.libertyrms.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200610/52 X-Sequence-Number: 21181 Also, the multikey index of (assetid, ts) would already be sorted and that is why using such an index in this case is faster than doing a sequential scan that does the sorting afterwards. Graham. Chris Browne wrote: >gdavis@refractions.net (Graham Davis) writes: > > >>Adding DESC to both columns in the SORT BY did not make the query use >>the multikey index. So both >> >>SELECT DISTINCT ON (assetid) assetid, ts >>FROM asset_positions ORDER BY assetid, ts DESC; >> >>and >> >>SELECT DISTINCT ON (assetid) assetid, ts >>FROM asset_positions ORDER BY assetid DESC, ts DESC; >> >>use the same query plans and both do sequential scans without using >>either the (assetid, ts) or (ts) indexes. Any other ideas on how to >>make this query use an index? Thanks, >> >> > >Why do you want to worsen performance by forcing the use of an index? > >You are reading through the entire table, after all, and doing so via >a sequential scan is normally the fastest way to do that. An index >scan would only be more efficient if you don't have enough space in >memory to store all assetid values. > > -- Graham Davis Refractions Research Inc. gdavis@refractions.net