FEAT: Optimize executemany() performance#138
Merged
gargsaumya merged 9 commits intomainfrom Jul 17, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces column-wise parameter binding optimization for the executemany() method in the mssql_python library to improve performance for batched SQL execution. The changes enable binding multiple parameter sets at once rather than executing each parameter set individually.
- Refactored Python
executemany()method to use column-wise parameter binding instead of iterative execution - Added C++ binding functions to support array parameter binding for various SQL data types
- Introduced helper functions for efficient parameter buffer allocation and memory management
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| mssql_python/cursor.py | Completely rewrote executemany() to transpose row-wise parameters to column-wise format and use new batched execution method |
| mssql_python/pybind/ddbc_bindings.cpp | Added BindParameterArray(), SQLExecuteMany_wrap(), and AllocateParamBufferArray() functions to support column-wise parameter binding |
a0aadfc to
16a2e58
Compare
16a2e58 to
4ea32c7
Compare
This reverts commit 4ea32c7.
bf67d3a to
42824f1
Compare
jahnvi480
previously approved these changes
Jul 16, 2025
bewithgaurav
previously approved these changes
Jul 16, 2025
bewithgaurav
previously approved these changes
Jul 16, 2025
jahnvi480
previously approved these changes
Jul 16, 2025
sumitmsft
reviewed
Jul 16, 2025
sumitmsft
reviewed
Jul 16, 2025
sumitmsft
reviewed
Jul 16, 2025
sumitmsft
reviewed
Jul 16, 2025
sumitmsft
reviewed
Jul 16, 2025
sumitmsft
reviewed
Jul 16, 2025
sumitmsft
reviewed
Jul 16, 2025
fd6e4ee to
c860e5d
Compare
bewithgaurav
approved these changes
Jul 17, 2025
jahnvi480
approved these changes
Jul 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADO Work Item Reference
Summary
This pull request introduces significant updates to the
executemanymethod in themssql_pythonlibrary to enable column-wise parameter binding for batched SQL execution. It also includes enhancements to the underlying C++ bindings to support this functionality. The most important changes involve implementing column-wise binding logic, adding helper functions for parameter buffer allocation, and exposing a newSQLExecuteManymethod for executing batched statements.Enhancements to Python
executemanymethod:mssql_python/cursor.py: Refactored theexecutemanymethod to use column-wise parameter binding for improved performance and scalability. Added_transpose_rowwise_to_columnwisehelper function to convert row-wise parameters into column-wise format.Updates to C++ bindings:
mssql_python/pybind/ddbc_bindings.cpp: AddedBindParameterArrayfunction to handle column-wise parameter binding, supporting multiple data types such asSQL_C_LONG,SQL_C_DOUBLE, andSQL_C_WCHAR.mssql_python/pybind/ddbc_bindings.cpp: IntroducedSQLExecuteMany_wrapfunction to enable batched execution of SQL statements with multiple parameter sets.mssql_python/pybind/ddbc_bindings.cpp: Exposed the newSQLExecuteManymethod to Python viaPYBIND11_MODULE.Helper functions for buffer allocation:
mssql_python/pybind/ddbc_bindings.cpp: AddedAllocateParamBufferArraytemplate function to allocate buffers for column-wise parameter binding.