OFFSET SQL Origin: Data OSI layer 7 · Application Last updated 18 Nov 2026

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.

Exact message you may see slow pagination large OFFSETOFFSET 100000 slow querydeep pagination performance SQLkeyset pagination vs offsetLIMIT OFFSET gets slower
Seen on: SQL MySQL PostgreSQL

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

  1. Switch to keyset pagination
  2. Add an index on the ORDER BY columns
  3. Cache or approximate total counts

Detailed fix by platform

SQL

  1. 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

  1. OFFSET — Large?
  2. Index — On sort key?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

57014 — ERROR: canceling statement due to statement timeout (PostgreSQL)57014cartesian — Query returns far too many rows: accidental Cartesian product (missing JOIN condition) (SQL)cartesianCASE — CASE expression returns mixed types: conversion failed / types cannot be matched (SQL)CASECOUNT — COUNT(column) ignores NULLs: counts differ from COUNT(*) (SQL)COUNTdate format — Dates mixed up: dd/mm/yyyy vs mm/dd/yyyy, ISO 8601 recommended (SQL)date formathotspotting — Firestore write latency/errors: hotspotting from sequential document IDs or indexed fields (Google Cloud / Firebase)hotspottingimplicit conversion — Query slow because of an implicit type conversion or function on the column (index not used) (SQL)implicit conversionindexOn — Realtime Database: Using an unspecified index — consider adding ".indexOn" to your security rules (Google Cloud / Firebase)indexOnOFFSET

Explore the map of this error Full error map →

🧠 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.