Skip site navigation (1) Skip section navigation (2)

Re: LIMIT Question

From: "Gurjeet Singh" <singh(dot)gurjeet(at)gmail(dot)com>
To: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
Cc: "Terry Lee Tucker" <terry(at)chosen-ones(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: LIMIT Question
Date: 2008-02-29 09:23:05
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
In my opinion (without looking at the code), if you have a grouping-function
or ORDER BY or GROUP BY clause, then yes, the whole query has to be executed
to show the first row of the result-set. But if the query doesn't have any
of these clauses, then the DB has the ability to send back the first row
from the result as soon as it processes it (i.e after WHERE clause
processing), and stop the query execution there.

Best regards,

On Fri, Feb 29, 2008 at 5:02 AM, Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>

> On Thu, Feb 28, 2008 at 3:20 PM, Terry Lee Tucker <terry(at)chosen-ones(dot)org>
> wrote:
> > When one uses LIMIT, as in LIMIT 1, is the entire query executed on the
> server
> >  side, but only one record returned?
> >
> >
>  --------------------------------------------------------------------------------------------------------
> >   PostgreSQL 7.4.19 on i686-redhat-linux-gnu, compiled by GCC gcc (GCC)
> 3.4.6
> >  20060404 (Red Hat 3.4.6-9)
> Sometimes yes, sometimes no.  Depends on how complex the query is and
> whether or not pgsql's query planner can see a shortcut or not.  It's
> more likely that a later version will have the optimizations needed to
> do that than an older version like 7.4 I'd think.  But I'd ask someone
> more expert on the planner like Tom to be sure.
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?

singh(dot)gurjeet(at){ gmail | hotmail | indiatimes | yahoo }.com


17° 29' 34.37"N,  78° 30' 59.76"E - Hyderabad
18° 32' 57.25"N,  73° 56' 25.42"E - Pune *
37° 47' 19.72"N, 122° 24' 1.69" W - San Francisco

Mail sent from my BlackLaptop device

In response to


pgsql-general by date

Next:From: Richard HuxtonDate: 2008-02-29 09:55:27
Subject: Re: Text Search zero padding
Previous:From: Oleg BartunovDate: 2008-02-29 08:06:40
Subject: Re: Text Search zero padding

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group