Re: Upgrading to 7.2

From: Doug McNaught <doug(at)wireboard(dot)com>
To: Chris Field <cfields(at)affinitysolutions(dot)com>
Cc: Postgresql <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Upgrading to 7.2
Date: 2002-02-14 17:27:10
Message-ID: m3n0ycotxt.fsf@varsoon.denali.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Chris Field <cfields(at)affinitysolutions(dot)com> writes:

> Thanks for responding, I am thinking it might be fairly beneficial to
> upgrade.
>
> > Ummm, max() is an aggregate function, how can you create an index on
> > it?
>
> In the postgresSQL Essential Reference by Barry Stinson it specifically
> has a index topic on functional indexes, with the given example being
> " CREATE INDEX max_payroll_idx ON payroll (MAX(salary)); "

This just seems wrong. MAX() is a function, not of a single value,
but of a set of values from a single column (ie it's an aggregate
function). Think about what an index is, and I think you'll see that
you can't build one on based on an aggregate function. It's not a
well-defined concept.

Think of it this way--an index is "a list of rows, organized by the
value of the index expression for each row." An aggregate function
like MAX() or SUM() doesn't have a useful value for a single row--it's
only meaningful in the context of a set of rows.

Non-aggregate functions (ie most of them, like sqrt(), sin(), cos()
etc) can definitely be used in indexes.

> so either the book was a waste of money, or this is a 7.2 specific
> feature.

The author does seem confused about this point, but the book still
might be worthwhile--haven't read it myself.

I might be totally out in left field here, but the reasoning above
makes sense to me at least. ;)

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
--T. J. Jackson, 1863

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chris Field 2002-02-14 17:33:55 Re: Upgrading to 7.2
Previous Message Tom Lane 2002-02-14 17:10:53 Re: [GENERAL] Postgres 7.2 - Updating rows in cursor problem