PostgREST pagination latency during high offset requests
0 reputation · 23 May 2025, 07:07 UTC
Supabase leverages PostgREST to translate API requests into SQL queries. When retrieving large datasets using the limit and offset parameters, the underlying PostgreSQL engine must scan and discard rows prior to returning the requested page.
As the offset value increases, there is a potential for linear degradation in query performance, leading to increased CPU utilization and higher response latency. This behavior is typical of standard SQL OFFSET clauses but becomes a critical bottleneck in high-concurrency environments with millions of records.
While keyset pagination is documented as a best practice for performance, the default SDK patterns often rely on offset-based navigation.
- What is the specific threshold where offset-based pagination begins to cause non-linear latency spikes in a standard Supabase instance?
- How can
pg_stat_statementsbe used to differentiate between slow index scans and the overhead caused specifically by high offset values?