From: Bruce Momjian <pgman@candle.pha.pa.us>
To: josh@agliodbs.com
Cc: Bruno Wolff III <bruno@wolff.to>
Cc: pgsql-sql@postgresql.org
Subject: Re: Two Index Questions
Date: Fri, 19 Jul 2002 14:27:58 -0400 (EDT)
Message-ID: <200207191827.g6JIRw603603@candle.pha.pa.us> (raw)
In-Reply-To: <200207191112.49885.josh@agliodbs.com>
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@candle.pha.pa.us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: pgman@candle.pha.pa.us, josh@agliodbs.com, bruno@wolff.to
Subject: Re: Two Index Questions
In-Reply-To: <200207191827.g6JIRw603603@candle.pha.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox