Re: LIMIT: does it cause the query to find all matching sets first?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: LIMIT: does it cause the query to find all matching sets first?
Date: 2002-09-30 15:12:57
Message-ID: 20020930151257.GA15432@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 30, 2002 at 23:15:43 +0900,
Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp> wrote:
> Does using LIMIT cause query execution to stop as soon as the LIMIT
> number of matches have been found, or are *all* the matching rows found
> first and then the first LIMIT number are returned?

Limit can speed things up. Even with an ordered by clause it can speed things
up (if there is an appropiate index). This can be used to quickly find
the maximum or minimum value of an indexed column.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-09-30 15:17:09 Re: [HACKERS] current_timestamp after queries
Previous Message Greg Copeland 2002-09-30 15:10:09 Re: [HACKERS] current_timestamp after queries