Re: LIMIT Optimization

From: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: "alexandre paes :: aldeia digital" <alepaes(at)aldeiadigital(dot)com(dot)br>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: LIMIT Optimization
Date: 2002-01-25 18:40:24
Message-ID: Pine.GSO.4.33.0201252132090.19023-100000@ra.sai.msu.su
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, 25 Jan 2002, Bruce Momjian wrote:

> alexandre paes :: aldeia digital wrote:
> > Hi,
> >
> > DB2, Sql Server and Oracle have a smart optimization sql-clause (DB2
> > example):
> >
> > SELECT * FROM <table> WHERE <cond> ORDER BY <order> OPTMIZATION FOR n ROWS
> >
> > The [OPTMIZATION FOR] clause turns the query fast by optimize the first "n"
> > rows.
> > If the query returns more than "n" rows, the query is slowest if compared
> > with a normal
> > query, but it does not have the limitation of PostgreSQL's LIMIT clause.
> >
> > I think that clause performs the search twice: one for optimize and other if
> > the # of rows
> > is great then "n".
> >
> > It's possible to include this in future releases of PostgreSQL ????
>
> So it forces our LIMIT optimization, without limiting the number of rows
> returned. That seems to be of questionable value. The only value I can
> see for it is for CURSOR queries but I don't think we can start
> returning rows from even a cursor until the entire query is done
> executing.

if I'm not mistaken, it's called partial sorting, when you stop
sorting process after getting desired number of rows specified by LIMIT clause.
it's extremely friendly for web applications, because 90% of users
just read the first page of results. We already discussed this feature
sometime during 7.1 dev and even made very crude patch. In our tests we
got performance win of factor 5-6 ( getting first 100 row from 1mln ).
We hope sometime we'll return to this.

>
>

Regards,
Oleg
_____________________________________________________________
Oleg Bartunov, sci.researcher, hostmaster of AstroNet,
Sternberg Astronomical Institute, Moscow University (Russia)
Internet: oleg(at)sai(dot)msu(dot)su, http://www.sai.msu.su/~megera/
phone: +007(095)939-16-83, +007(095)939-23-83

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2002-01-25 19:36:30 Re: LIMIT Optimization
Previous Message alexandre paes :: aldeia digital 2002-01-25 18:32:07 Re: LIMIT Optimization