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
refactor: remove order by clause when counting rows to improve performance #2030
refactor: remove order by clause when counting rows to improve performance #2030
Conversation
@tyt2y3 At your convenience, could you please review this PR? We are currently using sea-orm in our production environment, and the changes proposed in this PR are expected to significantly contribute to resolving performance bottlenecks. Your assistance in reviewing would be greatly appreciated. Thank you for your time and consideration. |
Thank you for the contribution. I think this is the right thing to do. Just being curious, what performance gains you saw on a typical vs worst case query? |
Thank you so much for your review. Table info (Our testing environment)
Result in our testing environmentWorst caseExecution Time: 2740 ms -> 840 ms Typycal caseIn the production environment, handling a significantly larger volume of data is expected. Therefore, it is anticipated that the worst-case scenario in terms of data quantity in the test environment would be equivalent to a typical case in the production environment. As a result, we have not measured the typical case in the test environment. |
Interesting, good to know!
That's usually the culprit haha |
Now I am pushing a commit to fix Clippy error. It will be reflected when GitHub status is back to normal. https://www.githubstatus.com/ |
GitHub is back now |
Great, I pushed my commits. Now I think this PR will pass CI. |
self.query.clone().reset_limit().reset_offset().to_owned(), | ||
self.query | ||
.clone() | ||
.reset_limit() | ||
.reset_offset() | ||
.clear_order_by() | ||
.to_owned(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only these lines are the main change. Others are changes to fix clippy&compile errors.
|
Sad, those clippy warnings seem to be very confusing |
Can you reset hard this PR to 3ef07ab ? I will merge that first. |
571b51d
to
3ef07ab
Compare
Sure, that's a good idea. I will create another PR to fix clippy errors. |
Done |
🎉 Released In 0.12.11 🎉Thank you everyone for the contribution! |
Purpose of this PR
To enhance performance. I have added a process to remove the order by clause in the
num_items
method of thePaginator
trait, which is not needed to count rows.Performance Measurement Results
Upon executing queries on test data available to me, a performance improvement of approximately three times was observed when the order by clause was removed. (Unfortunately, I cannot provide the data used here, but I hope for your understanding.) Testing environment is PostgreSQL 14.7.