Re: LIMIT: does it cause the query to find all matching sets first? - Mailing list pgsql-general

From Tom Lane
Subject Re: LIMIT: does it cause the query to find all matching sets first?
Date
Msg-id 21393.1033398467@sss.pgh.pa.us
Whole thread Raw
In response to LIMIT: does it cause the query to find all matching sets first?  (Jean-Christian Imbeault <jc@mega-bucks.co.jp>)
List pgsql-general
Jean-Christian Imbeault <jc@mega-bucks.co.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

pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: LIMIT: does it cause the query to find all matching sets first?
Next
From: Bruce Momjian
Date:
Subject: Re: LIMIT: does it cause the query to find all matching sets