-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
ENH: enable server side cursors when chunksize is set #56742
Conversation
Does postgres support this? It would be nice if we can add a test that asserts this actually happens. I suppose it would also be limited to only some of the drivers. I know the ADBC postgres driver does not implement this yet, guessing libpq does? |
Yes, postgres supports this. Please take a look at: Also note that what we need here is to avoid fetching all the results into the memory, so the title is a bit misleading. My understanding is that, even if the backend does not support server-side cursors,
Also note that SQLAlchemy by default buffers 1000 rows, which may be less efficient for small results.
Since this is mostly a memory optimization, I am not sure how to test this. I don't want to mock it as much as possible. If you have any ideas, I'm happy to add a test.
SQLAlchemy docs says server-side cursors is supported for "mysqlclient, PyMySQL, mariadbconnector dialects and may also be available in others" for Streaming may be supported by other databases too (snowflake does as far as I see).
My understanding is that server side cursors (aka named cursors) [in postgres] are created through SQL commands, so I am not sure if this needs libpq support. But I am not familiar with libpq and haven't used ADBC at all, so I maybe wrong here. Please see Server Side Cursors - psycopg. |
I have added a simple test to check for |
Probably the best way to assert this actually does something is to add a |
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Thanks for the pull request, but it appears to have gone stale. If interested in continuing, please merge in the main branch, address any review comments and/or failing tests, and we can reopen. |
I'm so sorry to disappear like this. A lot of things happening both personally and at work that I won't be able to get to it in the short time. If anyone wants to contribute, the only thing missing from this PR is a memory benchmark (although I don't think it's important). |
Please look at the previous attempts in #40796 and #46166. A lot of changes have happened since that PR. Since
SQLTable
(orPandasSQL
) seems polymorphic, I did not want to change the function signature ofexecute()
and noticed the use ofself.returns_generator
which can be used to use server-side cursors or not.doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.