Skip to content

Enable server side cursors #46166

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Performance improvements
- Performance improvement in :func:`merge` when left and/or right are empty (:issue:`45838`)
- Performance improvement in :meth:`DataFrame.join` when left and/or right are empty (:issue:`46015`)
- Performance improvement in :class:`DataFrame` and :class:`Series` constructors for extension dtype scalars (:issue:`45854`)
-
- Performance improvement in :meth:`io.sql.SQLDatabase.execute` which streams results when chunking is enabled (:issue:`40847`)

.. ---------------------------------------------------------------------------
.. _whatsnew_150.bug_fixes:
Expand Down
20 changes: 17 additions & 3 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,23 @@ def run_transaction(self):
else:
yield self.connectable

def execute(self, *args, **kwargs):
"""Simple passthrough to SQLAlchemy connectable"""
return self.connectable.execution_options().execute(*args, **kwargs)
def execute(self, chunksize: int = 0, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a return type

Copy link
Author

@J0 J0 Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do! Will also add references to relevant tests and add a test if needed

"""
Simple passthrough to SQLAlchemy connectable

Parameters
----------
chunksize : int, default 0
Specify the number of rows in each batch to be written at a time.
By default, all rows will be written at once.
"""
if chunksize > 0:
# See: https://pythonspeed.com/articles/pandas-sql-chunking/
return self.connectable.execution_options(stream_results=True).execute(
*args, **kwargs
)
else:
return self.connectable.execution_options().execute(*args, **kwargs)

def read_table(
self,
Expand Down