Re: limit and query planner - Mailing list pgsql-general

From Tom Lane
Subject Re: limit and query planner
Date
Msg-id 9055.1528225349@sss.pgh.pa.us
Whole thread Raw
In response to limit and query planner  (armand pirvu <armand.pirvu@gmail.com>)
Responses Re: limit and query planner
List pgsql-general
armand pirvu <armand.pirvu@gmail.com> writes:
> My question is: I suspect the limit simply limits the fethching to the first n-records retrieved and has no
implicationswhatsoever on the planner, meaning the planner ignores it. Am I right or wrong ? 

You're quite wrong.  The presence of a LIMIT causes the planner to prefer
"fast start" plans, since it will then optimize on the basis of picking
the lowest estimated cost to fetch the first N rows.  As an example,
you're more likely to get an ordered indexscan than a seqscan-and-sort
for small N, though there are many cases where seqscan-and-sort wins
if the need is to fetch the whole table.

            regards, tom lane


pgsql-general by date:

Previous
From: Chris Travers
Date:
Subject: Re: Code of Conduct plan
Next
From: Benjamin Scherrey
Date:
Subject: Re: Code of Conduct plan