armand pirvu <armand.pi...@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