Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Microsoft Dev Blog: "mssql-python vs pyodbc: Benchmarking SQL Server Performance"

未關閉
#554 3 則留言 1 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 2 天內回覆

@jahnvi480 已經在處理了。

開始於 2026年5月5日。

評估

這個 Issue 還沒有評估資料。

描述

enhancement inADO triage done under development

Discovered the mssql-python library and the microsoft dev blog comparing the performance of the library vs pyodbc here: https://devblogs.microsoft.com/python/mssql-python-vs-pyodbc-benchmarking-sql-server-performance/

So I started to look into and test replacing our current pyodbc-based implementation with mssql-python by switching from pyodbc/sqlalchemy with pandas.read_sql to the .arrow().to_pandas() functionality of the mssql-python library.
Using the arrow integration, I found some significant speed ups in our data getters. This is significant for some of our work flows which have been slow in the past using our current sql to python workflow (e.g. 15s vs 42s).

In testing, I have looked into all the various workflows to compare the two libraries:

  1. I have used our existing DBs and queries to test timings for
  • .fetchall(): pyodbc vs mssql_python
  • pyodbc vs mssql_python via sqlalchemy/pandas (the latest beta of sqlalchemy for mssql-python compatibility)
  • mssql-python via .arrow()
  1. Used the performance test script from the original blog article here: https://github.com/microsoft/mssql-python/blob/main/benchmarks/bench_mssql.py

For these tests I initially used our existing infrastructure with SQL Server 2019 and Python 3.10. However to test whether they played any factor, I also tried Python 3.13 and SQL Server 2025 (via a fresh docker container)

Going via pyarrow is always the fastest which seems to be no surprise and provides generally the best features like fully typed columns and future compatibility with other libraries which is perfect.

However in testing the other scenarios which are more of a fair test between pyodbc and mssql-python and comparing their equivalent functionality. I keep finding that pyodbc is either approximately as performant or quicker than mssql-pyodbc.

Here's a list of results using the tests from the article:

Operation                   pyodbc min  mssql min  Ratio(min)   pyodbc med  mssql med  Ratio(med)
----------------------------------------------------------------------------------------------------
SELECT                         57.83ms    58.22ms      0.99x (pyodbc)      65.94ms    67.01ms      0.98x (pyodbc)
INSERT                         14.43ms    16.22ms      0.89x (pyodbc)      17.05ms    18.86ms      0.90x (pyodbc)
UPDATE                         14.24ms    17.37ms      0.82x (pyodbc)      16.66ms    20.57ms      0.81x (pyodbc)
DELETE                          6.04ms     7.98ms      0.76x (pyodbc)       7.72ms    10.64ms      0.73x (pyodbc)
Complex query                   5.79ms     7.80ms      0.74x (pyodbc)       7.05ms     9.98ms      0.71x (pyodbc)
Multiple connections           67.30ms    86.74ms      0.78x (pyodbc)      74.46ms    98.73ms      0.75x (pyodbc)
Fetch one                       5.86ms     7.55ms      0.78x (pyodbc)       8.07ms     9.75ms      0.83x (pyodbc)
Fetch many                      5.78ms     7.81ms      0.74x (pyodbc)       6.78ms     9.62ms      0.70x (pyodbc)
Stored procedure                5.80ms     7.53ms      0.77x (pyodbc)       6.79ms     8.75ms      0.78x (pyodbc)
Nested query                    5.93ms     7.74ms      0.77x (pyodbc)       7.30ms     9.76ms      0.75x (pyodbc)
Large data set                  5.76ms     8.21ms      0.70x (pyodbc)       6.78ms     9.70ms      0.70x (pyodbc)
Join query                      6.13ms     8.50ms      0.72x (pyodbc)       7.61ms    10.19ms      0.75x (pyodbc)
Execute many                   22.56ms    21.60ms      1.04x (mssql)      27.91ms    26.57ms      1.05x (mssql)
100 inserts                   187.36ms    23.13ms      8.10x (mssql)     204.97ms    25.67ms      7.98x (mssql)
Transaction                    22.62ms    24.63ms      0.92x (pyodbc)      28.83ms    30.79ms      0.94x (pyodbc)
Update with join                5.83ms     7.52ms      0.77x (pyodbc)       7.18ms     9.15ms      0.78x (pyodbc)
Delete with join                5.45ms     7.80ms      0.70x (pyodbc)       6.54ms     9.10ms      0.72x (pyodbc)

And an example benchmark for one of our internal queries of 24 columns by:

  • 1709738 rows
    pyodbc fetchall        23.5540s
    mssql-python fetchall  37.0886s
    SQLAlchemy+pyodbc      41.9620s
    SQLAlchemy+mssql-py    53.1163s
    
  • 77712 rows
    pyodbc fetchall        1.0679s
    mssql-python fetchall  1.2697s
    SQLAlchemy+pyodbc      1.7786s
    SQLAlchemy+mssql-py    2.0846s
    

I am by no means a SQL expert so maybe there's something else which is going on which means mssql-python is not reaching it's peak speeds.

Questions:

  • Any ideas why I cannot not replicate something similar to the original benchmarks whereby there's at least a 2x speed up in most situations?
  • If there is some sort of performance regression here, does this mean the arrow integration could be even faster than it is now in this initial testing?

Spec Details:
Python version: 3.10.11 and 3.13.12
SQL Server Version: 2019 (existing) and 2025 (test docker container)
OS: Windows 10
python-mssql: 1.6.0
pyodbc: 5.3.0
sqlalchemy: 2.1.0b1

主要語言
Python
星號
478
分支
62
平均合併
3 天 19 分鐘
30 天內合併 PR
28

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/mssql-python 的其他 Issue

查看 microsoft/mssql-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。