Postgres OFFSET vs keyset: page 100,000 is 6,000x slower

On a 5-million-row Postgres table, OFFSET took 182 ms at page 100,000 and 776 ms at page 200,000, while keyset pagination stayed at 0.03 ms on every page.

Writing the keyset cursor with OR instead of a row-value comparison like (created_at, id) < (x, y) took 150 ms at page 100,000, almost as slow as OFFSET.

OFFSET returned 245 duplicate rows in a 50-page crawl with 5 inserts per page and missed 9 percent of rows after deletes; keyset returned none.

Read the full post

Read the full post