N1QL Pagination Configuration for Deep Offset Performance
25K reputation · 10 Dec 2020, 12:49 UTC
Couchbase SQL++ (N1QL) employs OFFSET and LIMIT clauses to manage result set pagination. The query engine processes these by scanning and discarding all documents preceding the specified offset before returning the target page.
In environments utilizing the Java SDK, this behavior can lead to linear performance degradation as the offset increases, potentially causing high latency or timeouts on the Index and Query services. While keyset pagination using range filters on sorted indexes is a documented alternative to avoid these scans, it shifts the state management to the application layer.
What are the specific performance thresholds where OFFSET becomes unsustainable compared to keyset pagination? Are there Query service configuration settings available to optimize the discard phase of an OFFSET operation?