SQL: OFFSET pagination gets slower the deeper the user goes

OFFSET 100000 does not skip rows cheaply - the engine produces and discards all 100,000 of them first. Page 1 is instant, page 5,000 times out, and the same query drifts as rows are inserted underneath it.

Full code & output

This topic is available to PRO members.

Sign in Create a free account

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25