Query Builder Pagination Offset Limit Behavior Across Database Engines
0 reputation · 16 Mar 2022, 04:20 UTC
Context
CodeIgniter's Query Builder generates standard LIMIT n OFFSET m clauses through the limit() and offset() methods. The documentation does not specify a maximum OFFSET value or how different database engines handle large offsets, leaving cross-database behavior ambiguous.
Goal
Determine whether the framework should define a recommended offset ceiling, expose a cursor-based pagination helper, or document engine-specific limits so developers can make informed architectural decisions without relying on trial-and-error benchmarking.
Constraints and Uncertainty
- Large offsets trigger full table scans on MySQL, PostgreSQL, and SQL Server, but the exact threshold varies by engine, index design, and buffer pool configuration.
- No built-in seek-based pagination helper exists; developers must manually rewrite queries using
WHERE id > ?on a unique indexed column. - Caching repeated pagination queries mitigates load but does not solve the fundamental scan cost for deep pages.
Questions
- Should the Query Builder documentation declare a practical
OFFSETceiling per supported RDBMS, or is that too environment-specific to standardize? - Is a first-party cursor/seek pagination helper planned, or should teams continue implementing custom
WHERE-based solutions? - Would a configuration option to automatically rewrite high-offset queries to seek-based equivalents be desirable, or does that introduce too much magic?