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

From: "listrec" <listrec(at)epecon(dot)de>
To: <cgg007(at)yahoo(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Index not being used in MAX function (7.2.3)
Date: 2003-06-11 15:50:58
Message-ID: PCEJJIGCHIJCOOOGFAFEGENICAAA.listrec@epecon.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I think this is a wonderful idea. I often wondered why max(column) makes a
full table scan.

B.T.W.: If your max column is indexed, use

select column from table order by column desc limit 1

which gives you the maximum value in no time at all.

Detlef

-----Ursprungliche Nachricht-----
Von: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org]Im Auftrag von Chris Gamache
Gesendet: Mittwoch, 11. Juni 2003 17:44
An: pgsql-general(at)postgresql(dot)org
Betreff: Re: [GENERAL] Index not being used in MAX function (7.2.3)

Wouldn't it make sense to optimize max() and min() for indexed columns? I
don't
know if I'm barking up the wrong tree, but would it be possible to create an
aggregate (o_max, o_min) to make the query planner treat it differently from
other aggregates? IMO, (if possible...) this would be a more elegant
solution
than SQL'ing around the "feature". If it is possible, it might be a nifty
contrib module, poised for inclusion in the production code. Any
takers/thoughts? :)

CG

--- Paulo Jan <admin(at)digital(dot)ddnet(dot)es> wrote:
> Jonathan Bartlett wrote:
> > Is your index a hash or btree?
> >
> > Jon
> >
>
>
> It's a btree, but anyway, I see that others have already answered my
> question. So it's a "feature" and not a bug? Hrmpf.
> (BTW, the code I was running wasn't written by me; it was part of
> Phorum, a PHP web posting board application. I'll try to patch it to
> make it use "SELECT id... ORDER BY id DESC LIMIT 1" and see how it goes).
>
>
>
> Paulo Jan.
> DDnet.
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2003-06-11 15:52:07 Re: [HACKERS] SAP and MySQL ... [and Benchmark]
Previous Message Edmund Dengler 2003-06-11 15:48:46 Re: Performance of query (fwd)