Re: optimizer question

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Hannu Krosing <hannu(at)tm(dot)ee>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Reinoud van Leeuwen <reinoud(at)xs4all(dot)nl>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: optimizer question
Date: 2001-10-12 16:13:24
Message-ID: 200110121613.f9CGDOT02186@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Bruce Momjian wrote:
> >
> > > "Reinoud van Leeuwen" <reinoud(at)xs4all(dot)nl> writes:
> > > > I have a table that contains almost 8 milion rows. The primary key is a
> > > > sequence, so the index should have a good distribution. Why does the
> > > > optimizer refuse to use the index for getting the maximum value?
> > >
> > > The optimizer has no idea that max() has anything to do with indexes.
> > > You could try something like
> > >
> > > select * from tab order by foo desc limit 1;
> >
> > Can we consider doing this optimization automatically?
>
> Only if we assume that people do not define their own max() that does
> something
> that can't be calculated using the above formula like calculating AVG().

I hadn't thought of that one. I can't imagine a max() that doesn't
match the ORDER BY collating.

Updated TODO item:

* Use indexes for min() and max() or convert to SELECT col FROM tab
ORDER BY col DESC LIMIT 1;

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2001-10-12 16:19:52 Re: Pre-forking backend
Previous Message Bruce Momjian 2001-10-12 15:59:41 Re: Unicode combining characters