Pagination gets slower on later pages (large OFFSET scans and discards rows)
LIMIT 20 OFFSET 200000 reads and throws away 200,000 rows before returning the page.
slow pagination large OFFSETOFFSET 100000 slow querydeep pagination performance SQLkeyset pagination vs offsetLIMIT OFFSET gets slower Meaning
OFFSET pagination costs grow with the page number and can return duplicates/misses when data changes. Use keyset (seek) pagination: WHERE (created_at, id) < (:last_created, :last_id) ORDER BY created_at DESC, id DESC LIMIT 20 with a supporting composite index.
Common causes
- Deep OFFSET values
- No index on the sort column
- Non-unique sort key causing duplicates between pages
- Counting total rows on every request
- ORM default pagination
⚡ Quick fix
- Switch to keyset pagination
- Add an index on the ORDER BY columns
- Cache or approximate total counts
Detailed fix by platform
SQL
SELECT * FROM posts WHERE (created_at, id) < ('2026-10-01 10:00', 8421) ORDER BY created_at DESC, id DESC LIMIT 20;
How to diagnose
- OFFSET — Large?
- Index — On sort key?
- Sort key — Unique?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in SQL
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 18 Nov 2026