Home / Companies / Clearbit / Blog / Post Details
Content Deep Dive

PostgreSQL offsets and pagination performance

Blog post from Clearbit

Post Details
Company
Date Published
Author
Alex MacCaw
Word Count
279
Company Posts That Month
3
Language
English
Hacker News Points
-
Post removed?
No
Summary

PostgreSQL struggles with performance issues when handling high offsets due to its need for a full table scan, which complicates pagination without excessive memory usage. While cursors might seem like a potential solution, they rely on transactions and can lead to memory exhaustion. A more effective approach involves using an indexed auto-incrementing ID for pagination purposes. At Clearbit, UUIDs are used for identifiers, but an internal indexed numeric sequence column (iid) is utilized for efficient pagination. This method involves selecting records based on the iid column rather than an OFFSET, leading to faster query execution. The implementation, demonstrated with a Sequel example, can be adapted to other ORMs and facilitates pagination by iterating over ordered records using a WHERE clause with the iid column, ensuring optimal performance with large datasets.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.