Lab 08 — Pagination
Scenario
An API requests 50 orders after skipping 400,000 rows. Although the response is small, offset pagination still requires PostgreSQL to visit and discard preceding entries.
Run the exercise
Investigate
- Compare execution at small and large offsets.
- Record rows processed versus rows returned.
- Check whether an index avoids sorting but not offset work.
- Design a stable keyset cursor using the ordering key.
- Consider duplicate sort values and concurrent inserts when choosing a cursor.
Diagnostic question
How does work grow with offset, and which plan metric proves that returning only 50 rows does not make the query cheap?