Re: LIMIT clause optimization

From: Felipe Schnack <felipes(at)ritterdosreis(dot)br>
To: Holger Klawitter <lists(at)klawitter(dot)de>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: LIMIT clause optimization
Date: 2003-01-07 12:44:15
Message-ID: 1041943455.6409.39.camel@desenv1.ritterdosreis.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Why? I don't understand. If I create a query and want just the first
row from it, wouldn't speed up things a lot just adding "LIMIT 1" in the
end of the query?

On Tue, 2003-01-07 at 10:44, Holger Klawitter wrote:
> Am Dienstag, 7. Januar 2003 12:47 schrieb Felipe Schnack:
> > I was wondering... (a newbie starting to understand how to optimize
> > queries)
> > In which step of query execution the LIMIT clause is executed? I mean
> > I have a query that would return, let's say, 6 rows, but I add a "LIMIT
> > 1" in the end of it.
> > I would speed up things because I would have less data fetching from
> > the database, right?
>
> Limit kicks in quite late as it has to be done after sorting. And it is not
> recommended to use LIMIT without ORDER BY.
>
> With kind regards / mit freundlichem Gruß
> Holger Klawitter
> --
> Holger Klawitter http://www.klawitter.de
> lists(at)klawitter(dot)de
--

Felipe Schnack
Analista de Sistemas
felipes(at)ritterdosreis(dot)br
Cel.: (51)91287530
Linux Counter #281893

Centro Universitário Ritter dos Reis
http://www.ritterdosreis.br
ritter(at)ritterdosreis(dot)br
Fone/Fax.: (51)32303341

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Holger Klawitter 2003-01-07 12:44:53 Re: LIMIT clause optimization
Previous Message Tomasz Myrta 2003-01-07 12:00:12 Re: [SQL] 7.3.1 index use / performance