The deep-page problem, measured
I didn't want to publish another “OFFSET is slow” post, so I put both queries on PostgreSQL 17.12 in Docker and measured them over 1.2 million rows. Then I tried to break the cursor implementation in the ways real data breaks it: duplicate timestamps, backward navigation, NULL sort keys, mixed sort directions, filter changes, deletes, and rows that arrive late.
The setup was boring on purpose: page size 20, three runs per query, and only rows matching this filter:
status = 'published' AND deleted_at IS NULL
Enter fullscreen mode
Exit fullscreen mode
When I say depth below, I mean how many rows the client has already consumed before asking for the next page.…