Offset latency with TypeORM QueryBuilder skip/take in NestJS
0 reputation · 20 Oct 2024, 09:24 UTC
Offset-based Pagination Latency
In a NestJS service using TypeORM QueryBuilder, offset-based pagination is commonly implemented with skip and take to bound result sets for large tables. The pattern is typically encapsulated in the service layer with DTO-validated page and limit parameters.
The unresolved behavior is performance degradation as skip grows, because the database must scan and discard preceding rows before returning the requested subset. Using skip and take with joined relations can also produce incorrect result counts unless a separate count query is applied. Query bounding via WHERE clauses and LIMIT/OFFSET remains the documented approach, but constant-time lookup guarantees are not established for high offsets.
- What mitigation options exist for high offset values without abandoning the current pagination structure?
- Which documented strategy within NestJS or TypeORM supports keyset pagination for constant-time lookups?
- Under what conditions does skip/take with joined relations require a separate count query to remain correct?