Re: select max(column) not using index

From: mlw <markw(at)mohawksoft(dot)com>
To: Thomas Zehetbauer <thomasz(at)hostmaster(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: select max(column) not using index
Date: 2002-03-13 16:03:31
Message-ID: 3C8F7853.C42CB2B4@mohawksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thomas Zehetbauer wrote:
>
> I think you all should really buy the book 'Database Development for Dummies'.
> Postgresql is for sure the only database on this planet that cannot optimize a
> select(max) using an index. Not even Microsoft has implemented such a design
> deficiency yet and even MySQL which you like to talk so bad about uses an
> index to optimize select max() queries. Some of you should really consider
> attending a programming course and all of you should consider to stop working
> on this totally screwed up monster!
>
> Tom

The query:

select max from table order by max desc limit 1

Will do it, but "max()" is by no means an easy to optimize function. Aggregates
have an assumption of a range scan, especially custom aggregates. What about
this:

select max(foo) from bar where x = 'y';

How is the index used in this query?

The only instance where an aggregate optimization would pay off is when there
is no selection criteria and there is an index on the field. In this case, it
is easy enough to create a function for the particular application.

I hear and understand your frustration, yes PostgreSQL should be able to do
that, and maybe it would be worth the time and effort, that is not for me to
say, however there is a very viable work around for the problem you state and
the stated problem, while a common query, is a small subset of the actual
capability of the max() function.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert E. Bruccoleri 2002-03-13 16:04:35 Re: bad performance on irix
Previous Message Luis Alberto Amigo Navarro 2002-03-13 15:45:17 Re: bad performance on irix