Re: Two Index Questions

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: Two Index Questions
Дата
Msg-id 200207191827.g6JIRw603603@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: Two Index Questions  (Josh Berkus <josh@agliodbs.com>)
Список 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 по дате отправления:

Предыдущее
От: Josh Berkus
Дата:
Сообщение: Re: Two Index Questions
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Two Index Questions