From: Tom Lane <tgl@sss.pgh.pa.us>
To: armand pirvu <armand.pirvu@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: limit and query planner
Date: Tue, 05 Jun 2018 15:02:29 -0400
Message-ID: <9055.1528225349@sss.pgh.pa.us> (raw)
In-Reply-To: <59ED87E7-B582-481A-9FD8-CB77C7A3B268@gmail.com>
References: <59ED87E7-B582-481A-9FD8-CB77C7A3B268@gmail.com>
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 implications whatsoever 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, armand.pirvu@gmail.com
Subject: Re: limit and query planner
In-Reply-To: <9055.1528225349@sss.pgh.pa.us>
References: <59ED87E7-B582-481A-9FD8-CB77C7A3B268@gmail.com> <9055.1528225349@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox