Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id CF88D9FB24C for ; Tue, 3 Oct 2006 17:48:22 -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 16771-04 for ; Tue, 3 Oct 2006 20:48:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 428AC9FB20B for ; Tue, 3 Oct 2006 17:48:12 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k93Km9oO010942; Tue, 3 Oct 2006 16:48:09 -0400 (EDT) To: gdavis@refractions.net cc: Chris Browne , pgsql-performance@postgresql.org Subject: Re: BUG #2658: Query not using index In-reply-to: <4522C8D8.4010601@refractions.net> References: <200609272056.k8RKuWjY040283@wwwmaster.postgresql.org> <20061003000147.GA31475@wolff.to> <4522AA01.4020709@refractions.net> <60irj1gr3r.fsf@dba2.int.libertyrms.com> <4522B5B9.2050206@refractions.net> <60d599gqcz.fsf@dba2.int.libertyrms.com> <4522C8D8.4010601@refractions.net> Comments: In-reply-to Graham Davis message dated "Tue, 03 Oct 2006 13:32:24 -0700" Date: Tue, 03 Oct 2006 16:48:09 -0400 Message-ID: <10941.1159908489@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200610/57 X-Sequence-Number: 21186 Graham Davis writes: > How come an aggreate like that has to use a sequential scan? I know > that PostgreSQL use to have to do a sequential scan for all aggregates, > but there was support added to version 8 so that aggregates would take > advantage of indexes. Not in a GROUP BY context, only for the simple case. Per the comment in planagg.c: * We don't handle GROUP BY, because our current implementations of * grouping require looking at all the rows anyway, and so there's not * much point in optimizing MIN/MAX. The problem is that using an index to obtain the maximum value of ts for a given value of assetid is not the same thing as finding out what all the distinct values of assetid are. This could possibly be improved but it would take a considerable amount more work. It's definitely not in the category of "bug fix". regards, tom lane