From: | Neil Conway <neilc(at)samurai(dot)com> |
---|---|
To: | Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org> |
Cc: | Shridhar Daithankar <shridhar_daithankar(at)persistent(dot)co(dot)in>, Paulo Scardine <paulos(at)cimed(dot)ind(dot)br>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Seqscan in MAX(index_column) |
Date: | 2003-09-04 15:49:30 |
Message-ID: | 1062690570.2233.5.camel@tokyo |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
This is an FAQ, BTW -- try searching the archives again. It's also
mentioned in the documentation:
http://candle.pha.pa.us/main/writings/pgsql/sgml/functions-aggregate.html
On Thu, 2003-09-04 at 11:10, Dennis Bjorklund wrote:
> On Thu, 4 Sep 2003, Shridhar Daithankar wrote:
> > It can not be cached, at least easily. That's the price to pay for MVCC. Same
> > goes for select count(*) from table. That query has to end up with a sequential
> > scan.
>
> It does not have to be like that. Even with a mvcc database it can use the
> index for max/min and in my opinion it should.
Right, AFAIK MVCC isn't relevant to MAX() (given a btree index, you can
just read the index in the right order and return the first valid
tuple), although it makes optimizing COUNT(*) trickier, I believe.
> As far as I know the only reason why it's not implemented in postgresql is
> because pg has a general aggregate model and max/min are implemented using
> that. Still, max/min are special in that they are almost the only
> aggregates that can use an index to deliver the result directly. Some day
> someone should make max/min a special case in pg. Exactly how is the
> question.
Well, it's an open question whether it's worth uglifying the backend to
support this optimization, given that there is a trivial workaround that
people can use. It would make it easier to port code to PostgreSQL from
other RDBMSs, though...
-Neil
From | Date | Subject | |
---|---|---|---|
Next Message | Czuczy Gergely | 2003-09-04 15:55:48 | Re: Seqscan in MAX(index_column) |
Previous Message | Bruce Momjian | 2003-09-04 15:14:34 | Re: Win32 native port |