LIMIT clause optimization

From: Felipe Schnack <felipes(at)ritterdosreis(dot)br>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: LIMIT clause optimization
Date: 2003-01-07 11:47:27
Message-ID: 1041940047.6599.12.camel@desenv1.ritterdosreis.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?
But let's go to a extreme case. I just want to check if a query
returns data at all, so I did the following query:
select 1 from <tablename>
Seems fair, right? And what would be the difference in query
optimization if I did the following (i know i'm doing strange stuff):
select 1 from <tablename> limit 1

--

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tomasz Myrta 2003-01-07 12:00:12 Re: [SQL] 7.3.1 index use / performance
Previous Message Dan Langille 2003-01-07 11:44:25 Re: [HACKERS] Have people taken a look at pgdiff yet?