From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | josh(at)agliodbs(dot)com |
Cc: | Bruno Wolff III <bruno(at)wolff(dot)to>, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Two Index Questions |
Date: | 2002-07-19 18:27:58 |
Message-ID: | 200207191827.g6JIRw603603@candle.pha.pa.us |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Josh Berkus wrote:
> Bruno, Tom,
>
> > Typo. I meant to say columns. The issue is that max doesn't use an index,
> > but if there are a lot of different values of G for a given A, B and C,
> > it may be better to use an index then to search through the applicable
> > rows to find the maximum.
>
> That's odd ... you're correct. Tom, why doesn't MAX() use an index? I
> understand why indexes are generally useless for SUM(), AVG, and COUNT, but
> it seems that MAX() and MIN() should *always* use an index.
Index access methods don't know about aggregates, and our type system
makes such linkage difficult. The FAQ does have:
However, <SMALL>LIMIT</SMALL> combined with <SMALL>ORDER BY</SMALL>
often will use an index because only a small portion of the table
is returned. In fact, though MAX() and MIN() don't use indexes,
it is possible to retrieve such values using an index with ORDER BY
and LIMIT:
<PRE>
SELECT col
FROM tab
ORDER BY col [ DESC ]
LIMIT 1
</PRE>
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-07-19 18:35:42 | Re: Two Index Questions |
Previous Message | Josh Berkus | 2002-07-19 18:12:49 | Re: Two Index Questions |