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 9687AD1B4E8 for ; Tue, 9 Sep 2003 19:07:58 +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 68058-01 for ; Tue, 9 Sep 2003 16:07:28 -0300 (ADT) Received: from stubee.d2hosting.net (d2hosting.net [66.70.41.160]) by svr1.postgresql.org (Postfix) with ESMTP id B0437D1B4E7 for ; Tue, 9 Sep 2003 16:07:21 -0300 (ADT) Received: from idigx.com ([208.207.88.112]) by stubee.d2hosting.net (8.11.6/linuxconf) with ESMTP id h89J6uM13783; Tue, 9 Sep 2003 14:06:57 -0500 Message-ID: <3F5E24D0.4040309@idigx.com> Date: Tue, 09 Sep 2003 14:06:56 -0500 From: Thomas Swan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5b) Gecko/20030901 Thunderbird/0.2 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: "scott.marlowe" , Neil Conway , =?ISO-8859-1?Q?Pailloncy_Jean-G=E9rard?= , PostgreSQL Performance Subject: Re: slow plan for min/max References: <3303.1063056376@sss.pgh.pa.us> In-Reply-To: <3303.1063056376@sss.pgh.pa.us> X-Enigmail-Version: 0.81.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/159 X-Sequence-Number: 3525 Tom Lane wrote: >"scott.marlowe" writes: > > >>On Mon, 8 Sep 2003, Neil Conway wrote: >> >> >>>As was pointed out in a thread a couple days ago, MIN/MAX() optimization >>>has absolutely nothing to do with MVCC. It does, however, make >>>optimizing COUNT() more difficult. >>> >>> > > > >>Not exactly. While max(id) is easily optimized by query replacement, >>more complex aggregates will still have perfomance issues that would not >>be present in a row locking database. i.e. max((field1/field2)*field3) is >>still going to cost more to process, isn't it? >> >> > >Er, what makes you think that would be cheap in any database? > >Postgres would actually have an advantage given its support for >expressional indexes (nee functional indexes). If we had an optimizer >transform to convert MAX() into an index scan, I would expect it to be >able to match up max((field1/field2)*field3) with an index on >((field1/field2)*field3). > > Would it be possible to rewrite min and max at the parser level into a select/subselect (clause) condition ( repeat condition ) order by (clause ) descending/ascending limit 1 and thereby avoiding the penalties of altering the default aggregate behavior? Would it yield anything beneficial?