Plan nodes · Grouping and sorting
Limit
Stops after the first N rows (LIMIT and OFFSET).
Returns at most the requested number of rows, skipping the OFFSET first, and then stops asking its child for more. Because of that, a plan under a Limit is chosen for how fast it returns its first rows, not all of them.
Example
SELECT * FROM tracks ORDER BY ms, name LIMIT 10
3 nodes
- Limitrows 10 (estimated 10) cost 0.37..1.45 buffers: 13 hit
- Incremental Sortrows 10 (estimated 100,000) cost 0.37..10876.29 buffers: 13 hitsort key
ms, namealready sorted onms- Index Scan using tracks_ms on tracksrows 11 (estimated 100,000) cost 0.29..6376.29 buffers: 13 hit1 index searches
Run with EXPLAIN (ANALYZE, BUFFERS, TIMING OFF, SUMMARY OFF) on the sample database, PostgreSQL 19.0. Open it in the EXPLAIN visualizer →
Related
Sort · Incremental Sort · Aggregate · Group · Unique · WindowAgg