首页 > 解决方案 > 如何提高对 2.64 亿行表的选择查询的性能?

问题描述

我正在使用一个 python 脚本,它使用 cursor.fetchmany(100000) 从我的数据库中提取数据。我正在使用的查询是select {column_name} from {table}. 我想对此数据执行组聚合,但是按查询分组似乎需要很长时间。因此,我决定使用 Python 代码通过将批量数据加载到内存中来执行计算。该表有 900 多列,我一次在 1 列上执行计算。

def get_data(cur,column_name):
    qry=f"select {column_name} from table"
    cur.execute(qry)
    while True:
        st=time.time()
        cur.fetchmany(100000)
        print(f"Time taken:{time.time()-st}")

标签: sql-server

解决方案


推荐阅读