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
optimization: paginate total count #281
Conversation
I don't think this actually improves performance, count is just generally slow and may already be optimized by the db. Would you add some benchmarks for at least PostgreSQL, MySQL, and SQLite that demonstrate this being a better implementation? |
generates SQL like this: |
|
I did an informal benchmark on a PostgreSQL system I have at work. The new query either performed as well or worse than the current query. I understand that the rendered statements are different, but I'm skeptical that the second performs better without some numbers to back it up. |
Thanks @davidism. Significantly worse or within the margin of error? @doublefloat Could you provide some numbers on a few different backends? |
I made a test for each query on MySQL:
First 1000 queris performed in 22.76 seconds, and the second 1000 queries in 5.67 seconds. |
i have a a hunch that this optimization will break on some of the more complex queries that sqlalchemy allows - (details like combining aggregations with having clauses) |
ping @zzzeek: can you see any consequences to changing the query in this way? |
I'd skip the session.execute(self.statement) aspect of it for sure, because it's unnecessary and you lose mapping information that is critical for session.get_bind(), and at least just say |
Perhaps we add a |
Goodness. I'm tempted to break the pagination API in v3 including a |
I agree, we should improve the pagination handling in general. Extracting the pagination functions has already been brought up in #265. There are some open issues regarding pagination that could probably be handled at the same time. This issue also duplicates #272. |
Let's do it. I'll make a new issue for doing this properly and close up those. |
@zzzeek Thank you for your information. It's thoughtless of me to change it. |
No problem, thanks for taking the time to explore this anyway. |
No description provided.