Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination: keyset #1170

Closed
irees opened this issue Aug 22, 2017 · 0 comments
Closed

Pagination: keyset #1170

irees opened this issue Aug 22, 2017 · 0 comments
Assignees

Comments

@irees
Copy link
Member

irees commented Aug 22, 2017

https://www.citusdata.com/blog/2016/03/30/five-ways-to-paginate/

When getting all SSPs for a particular operator or feed, very high OFFSET values can fail. For instance, Berlin offset 1,000,000 takes 20s, and higher values can take even longer:

transitland-4-5-0=> SELECT "current_schedule_stop_pairs".id FROM "current_schedule_stop_pairs" WHERE "current_schedule_stop_pairs"."operator_id" = 1661  ORDER BY "current_schedule_stop_pairs"."id" ASC LIMIT 10000 OFFSET 1000000;
Time: 20145.364 ms

Implement an alternative pagination method where we use the highest ID from the previous page. This is up to 100x faster:

transitland-4-5-0=> SELECT "current_schedule_stop_pairs".id FROM "current_schedule_stop_pairs" WHERE "current_schedule_stop_pairs"."operator_id" = 1661 AND current_schedule_stop_pairs.id >= 1706528300 ORDER BY "current_schedule_stop_pairs"."id" ASC LIMIT 10000;
Time: 297.223 ms

The query param can be sort_keymin=x or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant