Skip to content

FEAT: Optimize executemany() performance #138

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

Merged
merged 9 commits into from
Jul 17, 2025
Merged

Conversation

gargsaumya
Copy link
Contributor

@gargsaumya gargsaumya commented Jul 15, 2025

ADO Work Item Reference

AB#37935


Summary

This pull request introduces significant updates to the executemany method in the mssql_python library 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 new SQLExecuteMany method for executing batched statements.

Enhancements to Python executemany method:

  • mssql_python/cursor.py: Refactored the executemany method to use column-wise parameter binding for improved performance and scalability. Added _transpose_rowwise_to_columnwise helper function to convert row-wise parameters into column-wise format.

Updates to C++ bindings:

Helper functions for buffer allocation:

@Copilot Copilot AI review requested due to automatic review settings July 15, 2025 08:50
@github-actions github-actions bot added the pr-size: medium Moderate update size label Jul 15, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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

@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Jul 15, 2025
@gargsaumya gargsaumya force-pushed the saumya/perf-improvement branch from a0aadfc to 16a2e58 Compare July 15, 2025 08:57
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Jul 15, 2025
@gargsaumya gargsaumya force-pushed the saumya/perf-improvement branch from 16a2e58 to 4ea32c7 Compare July 15, 2025 09:05
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Jul 15, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Jul 15, 2025
@microsoft microsoft deleted a comment from Copilot AI Jul 15, 2025
@microsoft microsoft deleted a comment from Copilot AI Jul 15, 2025
@microsoft microsoft deleted a comment from Copilot AI Jul 15, 2025
@gargsaumya gargsaumya force-pushed the saumya/perf-improvement branch from bf67d3a to 42824f1 Compare July 15, 2025 17:27
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Jul 15, 2025
jahnvi480
jahnvi480 previously approved these changes Jul 16, 2025
bewithgaurav
bewithgaurav previously approved these changes Jul 16, 2025
@github-actions github-actions bot added the pr-size: medium Moderate update size label Jul 16, 2025
bewithgaurav
bewithgaurav previously approved these changes Jul 16, 2025
jahnvi480
jahnvi480 previously approved these changes Jul 16, 2025
@gargsaumya gargsaumya dismissed stale reviews from jahnvi480 and bewithgaurav via c860e5d July 17, 2025 06:26
@gargsaumya gargsaumya force-pushed the saumya/perf-improvement branch from fd6e4ee to c860e5d Compare July 17, 2025 06:26
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Jul 17, 2025
@microsoft microsoft deleted a comment from Copilot AI Jul 17, 2025
@microsoft microsoft deleted a comment from Copilot AI Jul 17, 2025
@microsoft microsoft deleted a comment from Copilot AI Jul 17, 2025
@microsoft microsoft deleted a comment from Copilot AI Jul 17, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Jul 17, 2025
@gargsaumya gargsaumya merged commit 03f8ee9 into main Jul 17, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-size: medium Moderate update size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants