Node.js · Middle · Question 74 of 75
Why is cursor-based pagination often better than OFFSET for large tables?
- 1Cursors return all rows at once
- 2
OFFSETis not supported by PostgreSQL - ✓Correct answer:
OFFSETmakes the database skip all earlier rows and shifts results when rows are inserted; a cursor (WHERE id > last_id) uses an index and stays stable
Explanation
Page 10,000 with OFFSET scans everything before it. The trade-off: cursors can't jump straight to page N.