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

Performance issues when using offset #284

Closed
alexgb opened this issue Feb 16, 2013 · 2 comments
Closed

Performance issues when using offset #284

alexgb opened this issue Feb 16, 2013 · 2 comments

Comments

@alexgb
Copy link

alexgb commented Feb 16, 2013

When issuing queries using offset, the generated SQL performs poorly.

Article.limit(20).offset(20)

Yields the following SQL, which takes 45 seconds to complete on a table with 100 million rows.

SELECT * FROM (
 SELECT raw_sql_.*, rownum raw_rnum_
 FROM (SELECT "ARTICLE".* FROM "ARTICLE") raw_sql_
)
WHERE raw_rnum_ between 21 and 40

It would be better if it generated this instead which takes only 50ms on the same table – a 900x improvement.

SELECT * FROM (
 SELECT raw_sql_.*, rownum raw_rnum_
 FROM (SELECT "ARTICLE".* FROM "ARTICLE" ) raw_sql_
 WHERE rownum <= 40
)
WHERE raw_rnum_ > 21
@alexgb
Copy link
Author

alexgb commented Feb 16, 2013

Actually this appears to be an issue with arel that is fixed in master.

@alexgb alexgb closed this as completed Feb 16, 2013
@eduardordm
Copy link

@alexgb would you have more info on that fix?

Edit:

rails/arel#99

rails/arel@d1c9c46

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

2 participants