Simon Willison’s Weblog

Subscribe

Tuesday, 16th August 2022

Efficient Pagination Using Deferred Joins (via) Surprisingly simple trick for speeding up deep OFFSET x LIMIT y pagination queries, which get progressively slower as you paginate deeper into the data. Instead of applying them directly, apply them to a “select id from ...” query to fetch just the IDs, then either use a join or run a separate “select * from table where id in (...)” query to fetch the full records for that page.

# 5:35 pm / sql, performance

2022 » August

MTWTFSS
1234567
891011121314
15161718192021
22232425262728
293031