Re: LIMIT Optimization - Mailing list pgsql-sql

From Tom Lane
Subject Re: LIMIT Optimization
Date
Msg-id 25891.1012103955@sss.pgh.pa.us
Whole thread Raw
In response to Re: LIMIT Optimization  (Bruce Momjian <pgman@candle.pha.pa.us>)
Responses Re: LIMIT Optimization  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-sql
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> I am confused.  I thought we already did optimization for LIMIT that 
> assumed you only wanted a few values.  Is there something we are missing
> there?

Yeah, he was proposing an alternative implementation of sorting that
would win in a scenario like
SELECT ... ORDER BY foo LIMIT <something small>

If you have an index on foo then there's no problem, but if you're
forced to do an explicit sort then the system does a complete sort
before you can get any data out.  If the limit is small enough you
can instead do a one-pass "select top N" scan.

Note that this is only workable in the non-cursor case, where you
know the limit for sure.
        regards, tom lane


pgsql-sql by date:

Previous
From: pgsql
Date:
Subject: options for no multiple rows?
Next
From: Bruce Momjian
Date:
Subject: Re: LIMIT Optimization