| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | armand pirvu <armand(dot)pirvu(at)gmail(dot)com> |
| Cc: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: limit and query planner |
| Date: | 2018-06-05 19:02:29 |
| Message-ID: | 9055.1528225349@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
armand pirvu <armand(dot)pirvu(at)gmail(dot)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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Benjamin Scherrey | 2018-06-05 19:06:24 | Re: Code of Conduct plan |
| Previous Message | Chris Travers | 2018-06-05 18:53:37 | Re: Code of Conduct plan |