X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id AC8BED1B506 for ; Tue, 9 Sep 2003 18:44:02 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 63552-01 for ; Tue, 9 Sep 2003 15:43:32 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 835C7D1B504 for ; Tue, 9 Sep 2003 15:43:30 -0300 (ADT) Received: (qmail 15002 invoked by uid 500); 9 Sep 2003 18:49:54 -0000 Date: Tue, 9 Sep 2003 13:49:54 -0500 From: Bruno Wolff III To: Greg Stark Cc: "scott.marlowe" , Neil Conway , =?iso-8859-1?B?PT9pc28tODg1OS0xP3E/IFBhaWxsb25jeSBKZWFuLUfpcmFyZD89?= , PostgreSQL Performance Subject: Re: slow plan for min/max Message-ID: <20030909184954.GA14198@wolff.to> Mail-Followup-To: Greg Stark , "scott.marlowe" , Neil Conway , =?iso-8859-1?Q?=3D=3Fiso-8859-1=3Fq=3F_Pailloncy_Jean-G?= =?iso-8859-1?B?6XJhcmQ/PQ==?= , PostgreSQL Performance References: <87ad9d52dv.fsf@stark.dyndns.tv> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87ad9d52dv.fsf@stark.dyndns.tv> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/158 X-Sequence-Number: 3524 On Tue, Sep 09, 2003 at 12:54:04 -0400, Greg Stark wrote: > > So what would it take to implement this for "all" aggregates? Where I think > "all" really just means min(), max(), first(), last(). There can be other aggregates where indexes are helpful. The case of interest is when functions such that if the new item is contains the current value of the aggregate then the new value of the aggregate with be that of the current item. This allows you to skip looking at all of the other items contained in the current item. Dual problems can also benefit in a similar manner. In a case where the set is totally ordered by the contains index (as is the case or max and min) then the problem is even simpler and you can use the greatest or least element as appropiate.