SQL · performance
no-offset-pagination
sql:no-offset-pagination OFFSET pagination — use cursor pagination (WHERE id > :cursor).
- Code
- SARJ107
- Default
- error
- Fix
- none
- Languages
- sql
Why
OFFSET scans and discards every skipped row, so later pages become slower as the result set grows.
Fix
Filter on a stable cursor column, preserve its ordering, and retain a bounded LIMIT.
Before / after
Executed by this rule’s unit tests.
Before
Pagination that scans skipped rows
SELECT id FROM call ORDER BY id LIMIT 50 OFFSET 100;
After
Pagination bounded by a stable cursor
SELECT id FROM call WHERE id > :cursor ORDER BY id LIMIT 50;
Limits
- The rule recognizes literal and common driver parameter markers following OFFSET.
Formerly: no-limit-offset