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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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:07:47
Message-ID: 21393.1033398467@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp> writes:
> 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?

The current implementation actually stops after fetching, or at least
trying to fetch, one more row than the LIMIT+OFFSET sum. The extra row
is for internal convenience (keeps the direction-reversal logic in
nodeLimit.c simple). Some people have complained about that, but no
one's gotten annoyed enough to rewrite nodeLimit to avoid it.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2002-09-30 15:08:02 Re: LIMIT: does it cause the query to find all matching sets
Previous Message Bruce Momjian 2002-09-30 15:02:55 Re: current_timestamp after queries