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

Inconsistent results when paginating #1040

Open
charltongroves opened this issue Nov 3, 2020 · 1 comment
Open

Inconsistent results when paginating #1040

charltongroves opened this issue Nov 3, 2020 · 1 comment

Comments

@charltongroves
Copy link

Ran into a very puzzling issue when using .page

Plucking specific columns (eg, SELECT "organisations"."id" FROM "organisations") using pagination leads to a different set of data than loading the whole record (eg, SELECT "organisations".* FROM "organisations").
image

This is very bad as demonstrated by the use case

orgs = Organisation.page(1).per(20)
...
org_ids = Organisation.page(1).per(20).pluck(:id)

As a developer you would expect the results of those to be consistent, but they lead to completely different data as shown in the screenshot.

Enforcing a .order(:id) fixes the issue, but since your gem shows many use cases without using order it should be assumed that you dont have to use order to get consistent results.

@charltongroves
Copy link
Author

charltongroves commented Nov 3, 2020

I think i found the issue

When using limit/offset without an order_by you get indeterminate results depending on the how SQL optimises the query in the query plan
image

I would suggest updating your docs to encourage people to use order at all times when using .page

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