Re: Two Index Questions - Mailing list pgsql-sql

From Bruce Momjian
Subject Re: Two Index Questions
Date
Msg-id 200207191827.g6JIRw603603@candle.pha.pa.us
Whole thread Raw
In response to Re: Two Index Questions  (Josh Berkus <josh@agliodbs.com>)
List 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()
andMIN() 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@candle.pha.pa.us               |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-sql by date:

Previous
From: Josh Berkus
Date:
Subject: Re: Two Index Questions
Next
From: Tom Lane
Date:
Subject: Re: Two Index Questions