Plan operator
Limit
Plan node that stops requesting rows from its child once a row count has been produced.
A Limit node sits on top of another node and stops pulling rows from it once the requested count is reached. This is what makes LIMIT 10 cheap on top of an Index Scan — only ten rows are ever read.
The catch is that Limit is only cheap when the child can stream rows in the required order without materializing the full result. A Sort underneath a Limit still has to consider every row, though PostgreSQL uses a special bounded heap (top-N sort) that keeps memory proportional to the limit.
When LIMIT queries are slow, look for a Sort that is sorting much more data than the limit, and consider adding an index that produces rows pre-sorted.