sql-server - 如何提高对 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}")
解决方案
推荐阅读
- gtk - 在 Gtk 中创建表
- ios - NSBluetoothAlwaysUsageDescription 在 iOS 13.5 的 info.plist 中不可用
- php - 如何从特定日期获取上周一
- python - 为了让三明治机问题更有效,我应该做些什么改变?
- python - python setup tools - 从项目中安装子包
- android - 加载没有顶点缓冲区对象的法线不起作用OpenGL ES
- c - 具有不同类型参数的可变参数函数传递给它
- html - 降低叠加图像的不透明度
- javascript - Click 功能在 IE11 上不起作用
- python - 使用 PonyORM 和 FastAPI 列出