Re: Index not being used in MAX function (7.2.3)

From: "Dann Corbit" <DCorbit(at)connx(dot)com>
To: "Bruno Wolff III" <bruno(at)wolff(dot)to>, "Jonathan Bartlett" <johnnyb(at)eskimo(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, <jim(at)nasby(dot)net>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Index not being used in MAX function (7.2.3)
Date: 2003-06-11 18:41:26
Message-ID: D90A5A6C612A39408103E6ECDD77B829408B18@voyager.corporate.connx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: Bruno Wolff III [mailto:bruno(at)wolff(dot)to]
> Sent: Wednesday, June 11, 2003 11:30 AM
> To: Jonathan Bartlett
> Cc: Tom Lane; Dann Corbit; jim(at)nasby(dot)net; pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] Index not being used in MAX function (7.2.3)
>
>
> On Wed, Jun 11, 2003 at 10:44:22 -0700,
> Jonathan Bartlett <johnnyb(at)eskimo(dot)com> wrote:
> > I wonder if a macro system might be warranted - then have max be a
> > macro instead of an aggregate. However, I don't know
> exactly how that
> > would work since it involves the whole statement. Anyway, just an
> > idea to hopefully spur someone else's thinking cap :)
>
> I don't think that would work. There are going to be some
> cases where the aggregate is better than the subselect (and
> not just when there isn't an appropiate index). And in some
> cases distinct on order by may be the best way to get what you want.

Isn't that the optimizer's job to figure out? The whole idea of SQL is
to abstract the queries and allow the optimizer to make all the smart
choices about plans and stuff.

I do realize that it is very "non-trivial" to implement, but min() and
max() are used so often it seems it might be useful.

Here are some "free to use" templates for statistical functions:
ftp://cap.connx.com/tournament_software/Kahan.Hpp
ftp://cap.connx.com/tournament_software/STATS.HPP

The Kahan template is an extremely accurate adder (does not lose
precision like direct summation).
The Stats template (which uses the Kahan adder) does all sorts of things
like skew, kurtosis, min, max, stddev, average, count, sum etc. all
simultaneously.
Our product uses a similar template to produce all kinds of useful
statistical information. See:
http://www.connx.com/products/connx/Connx%208.8%20UserGuide/connxcdd32.h
tm
And look at the statistical functions book.

No, we don't do the optimization I have suggested for min/max, but I
hope to poke it into our tool set some day. However, we do have a
function called "sortfirst()" and a function called "sortlast() " both
of which do perform the suggested optimizations [when possible].

Perhaps PostgreSQL could do something similar.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kaarel 2003-06-11 19:01:46 Re: Postgres performance comments from a MySQL user
Previous Message Williams, Travis L, NPONS 2003-06-11 18:39:05 Performance question..