I usually paginate database tables by ordering by the Primary Key Column, with a query like ORDER BY id WHERE id > 12000 LIMIT 1000 which does not noticeably slow down as you get further into the database, unlike using OFFSET which does.

I would like to be able to paginate databases on tables that contain multiple Primary Key's just as fast, however, I'm not sure how I would write a query like this, as both columns could have ordering that is not related to each other.

Is there a known efficient way to paginate databases with multiple pk's?

0 Answers