Re: select max(column) not using index - Mailing list pgsql-hackers

From Hannu Krosing
Subject Re: select max(column) not using index
Date
Msg-id 1016036094.30674.8.camel@taru.tm.ee
Whole thread Raw
In response to select max(column) not using index  (Thomas Zehetbauer <thomasz@hostmaster.org>)
List pgsql-hackers
On Thu, 2002-03-07 at 18:04, 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.

PostgreSQL is extensible enough that luser can define max() to mean
anything and thus you don't have a general way to optimise it without
breaking some cases.

If you know that max(x) means the biggest x there is and you have a
b-tree index on x you can use:

select x from t order by x desc limit 1;

> Not even Microsoft has implemented such a design deficiency yet and 

It would be a very microsofty way to optimise in ways that sometimes
produce wrong results ;)

> even MySQL which you like to talk so bad about uses an
> index to optimize select max() queries. 

What do you need the superfast max() for ?

If you are trying to re-implement sequences you may yet find some
surprises.

> 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!
Did you make yourself look bad by assuming that postgreSQL _does_ your
suggested optimisation ?
> Nirvana: Zustand des Gluecks durch Ausloeschung des Selbst.

How is this related to above ??

-------------
Hannu



pgsql-hackers by date:

Previous
From: mlw
Date:
Subject: Re: a vacuum thread is not the answer
Next
From: Jean-Paul ARGUDO
Date:
Subject: Survey results on Oracle/M$NT4 to PG72/RH72 migration