Re: Seqscan in MAX(index_column)

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Seqscan in MAX(index_column)
Date: 2003-09-04 17:19:58
Message-ID: 200309041719.h84HJwa28484@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greg Stark wrote:
> It has nothing to do with MVCC. It has to do with implementing this is hard in
> the general case.
>
> Think of examples like:
>
> select max(foo) group by bar;
>
> or
>
> select max(foo) where xyz = z;
>
> To do it properly max/min have to be special-cased and tightly integrated with
> other code to handle index scans and aggregates. As it currently stands
> they're implemented the same way as any other aggregate, which means they get
> to see all the records in the grouping.
>
> This is a frequently asked question, I'm surprised you didn't find stuff
> searching with google. There have been numerous long discussions on this topic
> not long ago. People are still trying to think about how to handle this
> better.

The FAQ does have the example of using ORDER BY LIMIT 1 for MAX(). What
we don't have a workaround for is COUNT(*). I think that will require
some cached value that obeys MVCC rules of visibility.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2003-09-04 17:20:01 Re: Win32 native port
Previous Message Peter Eisentraut 2003-09-04 17:18:57 Re: TCP/IP with 7.4 beta2 broken?