Repository navigation
cursor.execute() with many bound parameters (~2000) is ~14x slower than pyodbc #500
Copy link
Copy link
Open
Labels
area: performanceThroughput, latency, GIL retention, large-param slowness, expensive round-trips, perf-regressionsThroughput, latency, GIL retention, large-param slowness, expensive round-trips, perf-regressionstriage doneIssues that are triaged by dev team and are in investigation.Issues that are triaged by dev team and are in investigation.under development
Description
Activity
Hi Daniel Caspi (@dxdc), thank you for opening this issue!
Our team will review it shortly. We aim to triage all new issues within 24-48 hours and get back to you.
If you have additional information to share, please feel free to update the issue.
Thank you for your patience!
- addedtriage neededFor new issues, not triaged yet.For new issues, not triaged yet.
on Apr 7, 2026 bewithgaurav commented
on Apr 10, 2026 CollaboratorMore actionsDaniel Caspi (@dxdc) - thanks a lot for raising the issue & posting the details
checked the original sqlalchemy thread as well
there are a few code paths which are currently expensive and we're optimizing them.
marking this as triage done, and we'll keep this issue posted as we go
thanks again!Reacted by Daniel Caspi- addedtriage doneIssues that are triaged by dev team and are in investigation.Issues that are triaged by dev team and are in investigation.and removedtriage neededFor new issues, not triaged yet.For new issues, not triaged yet.
on Apr 10, 2026 - added a commit that references this issue
on Apr 17, 2026 - added a commit that references this issue
on Apr 29, 2026 - addedarea: performanceThroughput, latency, GIL retention, large-param slowness, expensive round-trips, perf-regressionsThroughput, latency, GIL retention, large-param slowness, expensive round-trips, perf-regressions
on Jun 4, 2026 - added a commit that references this issue
on Aug 14, 2026 - added a commit that references this issue
on Sep 7, 2026
Metadata
Metadata
Assignees
Labels
area: performanceThroughput, latency, GIL retention, large-param slowness, expensive round-trips, perf-regressionsThroughput, latency, GIL retention, large-param slowness, expensive round-trips, perf-regressionstriage doneIssues that are triaged by dev team and are in investigation.Issues that are triaged by dev team and are in investigation.under development
Describe the bug
When executing a multi-row INSERT with ~2000 bound parameters (the kind SQLAlchemy's
insertmanyvaluesgenerates),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 singlecursor.execute()calls with large parameter counts.To reproduce
Output
Context
This came up while working on SQLAlchemy integration. SA 2.x uses
insertmanyvaluesby 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) andcursor.bulkcopy()is excellent (~390K rows/s). It's really just the many-parametercursor.execute()path that's slow.Environment