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

Re: LIMIT Question

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: LIMIT Question
Date: 2008-02-29 13:50:28
Message-ID: 20080229135027.GM1653@frubble.xen.chris-lamb.co.uk (view raw or flat)
Thread:
Lists: pgsql-general
On Fri, Feb 29, 2008 at 05:28:29PM +0530, Gurjeet Singh wrote:
> On Fri, Feb 29, 2008 at 3:55 PM, Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
> > Except if you have an index on the column you're ordering by. Then the
> > server can really return the first row quickly.
> 
> Quickly for sure... but I don't think 'without processing all the rows that
> qualify'.

Postgres will always try to do the smallest amount of work possible.
Putting a LIMIT in will cause the planner to pick a plan that returns an
appropriate number of rows quickly, sometimes it can be a very different
plan.

> I think it will still process all the rows and return just one.

How do you explain that when you run:

  SELECT 1/v FROM (VALUES (1),(0)) c(v);

Without a limit you get a "division by zero" exception, and when you
have a limit of one row you get a result back.


  Sam

In response to

Responses

pgsql-general by date

Next:From: Scott MarloweDate: 2008-02-29 14:15:45
Subject: Re: rule question
Previous:From: Gurjeet SinghDate: 2008-02-29 11:58:29
Subject: Re: LIMIT Question

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