cursor.execute() with many bound parameters (~2000) is ~14x slower than pyodbc
Maintainer thường phản hồi trong vòng 1 ngày
@bewithgaurav đang làm issue này rồi.
Từ ngày 9/4/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Describe the bug
When executing a multi-row INSERT with ~2000 bound parameters (the kind SQLAlchemy's insertmanyvalues generates), cursor.execute() is about 14x slower than the equivalent call through pyodbc.
cursor.executemany() is much closer between drivers (~1.6x), so the issue is specific to single cursor.execute() calls with large parameter counts.
To reproduce
import time
import mssql_python
import pyodbc
N = 100_000
COLS = 2
# ~1049 rows per INSERT, ~2098 params per call, ~95 calls total
ROWS_PER_BATCH = 2099 // COLS
SQL = "INSERT INTO bench (id, name) VALUES " + ",".join(
[f"(?, ?)"] * ROWS_PER_BATCH
)
PARAMS = [None] * (ROWS_PER_BATCH * COLS)
# --- mssql-python ---
conn = mssql_python.connect(
"SERVER=localhost;DATABASE=master;UID=sa;PWD=YourPassword;"
"Encrypt=yes;TrustServerCertificate=yes;"
)
cursor = conn.cursor()
cursor.execute(
"IF OBJECT_ID('bench') IS NOT NULL DROP TABLE bench;"
"CREATE TABLE bench (id INT, name VARCHAR(50))"
)
conn.commit()
t0 = time.perf_counter()
for _ in range(N // ROWS_PER_BATCH):
cursor.execute(SQL, PARAMS)
conn.commit()
ms_time = time.perf_counter() - t0
cursor.close()
conn.close()
# --- pyodbc ---
conn2 = pyodbc.connect(
"DRIVER={ODBC Driver 18 for SQL Server};"
"SERVER=localhost;DATABASE=master;UID=sa;PWD=YourPassword;"
"Encrypt=yes;TrustServerCertificate=yes;"
)
cursor2 = conn2.cursor()
cursor2.execute("TRUNCATE TABLE bench")
conn2.commit()
t0 = time.perf_counter()
for _ in range(N // ROWS_PER_BATCH):
cursor2.execute(SQL, PARAMS)
conn2.commit()
py_time = time.perf_counter() - t0
cursor2.close()
conn2.close()
print(f"mssql-python: {ms_time:.2f}s ({N / ms_time:,.0f} rows/s)")
print(f"pyodbc: {py_time:.2f}s ({N / py_time:,.0f} rows/s)")
Output
mssql-python: 11.87s (8,427 rows/s)
pyodbc: 0.77s (130,000 rows/s)
Context
This came up while working on SQLAlchemy integration. SA 2.x uses insertmanyvalues by default, which generates batched multi-row INSERTs with ~2098 parameters per call (limited by SQL Server's 2100 parameter cap).
For reference, cursor.executemany() is much faster on this driver (~50K rows/s) and cursor.bulkcopy() is excellent (~390K rows/s). It's really just the many-parameter cursor.execute() path that's slow.
Environment
- mssql-python: 1.4.0
- pyodbc: 5.2.0
- SQL Server: 2022
- Python: 3.12
- OS: Ubuntu 24.04
- Ngôn ngữ chính
- Python
- Star
- 478
- Fork
- 62
- Merge trung bình
- 3 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 27
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/mssql-python
-
area: bulk-copy
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microsoft/mssql-python#843 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
macOS: encrypted connections fail after Homebrew moved the `openssl` alias to `openssl@4`Có thể đã có người làm @bewithgaurav đã nhận 14 ngày trước. Đang mởarea: packaging-platform bug triage needed
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
microsoft/mssql-python#826 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bulkcopy PyCore login is closed by SQL Server 2019 while ODBC and Go clients succeed (1.14.0)Có thể làm lại được @bewithgaurav đã nhận 34 ngày trước và không có pull request nào đang mở. Đang mởarea: bulk-copy bug triage done
microsoft/mssql-python#750 · 4 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Announcement: mssql-python is coming to Django through mssql-django 2.0Có thể làm lại được @bewithgaurav đã nhận 40 ngày trước và không có pull request nào đang mở. Đang mởannouncement
microsoft/mssql-python#748 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Connection pool can briefly exceed max_size when pooling is disabled under loadCó thể đã có người làm @bewithgaurav đã nhận 23 ngày trước. Đang mởarea: connectivity-auth bug triage done under development
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
microsoft/mssql-python#746 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/mssql-python
Issue tương tự
-
[Bug]: LangGraph Store sync put bypasses namespace validationCó thể đã có người làm @ktz03 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
volcengine/OpenViking#6050 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Streamed /v1/chat/completions sends unredacted agent error text (keys) in the final chunkCó thể đã có người làm @rodricksz4h5 đã nhận hôm nay. Đang mởarea/streaming comp/gateway P2 type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NousResearch/hermes-agent#138245 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[oblt-aw][autodoc] Update user onboarding guide for mandatory trigger CODEOWNERS stepCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
correction metadata
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 68/100
acl-org/acl-anthology#10378 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
cloudtrail_multi_region_enabled_logging_management_events fails when the advanced event selector has a custom nameCó thể đã có người làm @12YYCCYY16 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
prowler-cloud/prowler#13033 ·
Maintainer thường phản hồi trong vòng 1 ngày